aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c57
1 files changed, 35 insertions, 22 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 651cc011..a93d9f44 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -12,6 +12,7 @@
12#include "sway/output.h" 12#include "sway/output.h"
13#include "sway/tree/arrange.h" 13#include "sway/tree/arrange.h"
14#include "sway/tree/container.h" 14#include "sway/tree/container.h"
15#include "sway/tree/view.h"
15#include "sway/tree/workspace.h" 16#include "sway/tree/workspace.h"
16#include "list.h" 17#include "list.h"
17#include "log.h" 18#include "log.h"
@@ -50,7 +51,7 @@ struct sway_container *workspace_create(struct sway_container *output,
50 output = get_workspace_initial_output(name); 51 output = get_workspace_initial_output(name);
51 } 52 }
52 53
53 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); 54 wlr_log(WLR_DEBUG, "Added workspace %s for output %s", name, output->name);
54 struct sway_container *workspace = container_create(C_WORKSPACE); 55 struct sway_container *workspace = container_create(C_WORKSPACE);
55 56
56 workspace->x = output->x; 57 workspace->x = output->x;
@@ -108,9 +109,8 @@ static bool workspace_valid_on_output(const char *output_name,
108} 109}
109 110
110char *workspace_next_name(const char *output_name) { 111char *workspace_next_name(const char *output_name) {
111 wlr_log(L_DEBUG, "Workspace: Generating new workspace name for output %s", 112 wlr_log(WLR_DEBUG, "Workspace: Generating new workspace name for output %s",
112 output_name); 113 output_name);
113 int l = 1;
114 // Scan all workspace bindings to find the next available workspace name, 114 // Scan all workspace bindings to find the next available workspace name,
115 // if none are found/available then default to a number 115 // if none are found/available then default to a number
116 struct sway_mode *mode = config->current_mode; 116 struct sway_mode *mode = config->current_mode;
@@ -137,7 +137,7 @@ char *workspace_next_name(const char *output_name) {
137 while (isspace(*_target)) { 137 while (isspace(*_target)) {
138 memmove(_target, _target+1, strlen(_target+1)); 138 memmove(_target, _target+1, strlen(_target+1));
139 } 139 }
140 wlr_log(L_DEBUG, "Got valid workspace command for target: '%s'", 140 wlr_log(WLR_DEBUG, "Got valid workspace command for target: '%s'",
141 _target); 141 _target);
142 142
143 // Make sure that the command references an actual workspace 143 // Make sure that the command references an actual workspace
@@ -163,7 +163,7 @@ char *workspace_next_name(const char *output_name) {
163 temp[length - 1] = '\0'; 163 temp[length - 1] = '\0';
164 free(_target); 164 free(_target);
165 _target = temp; 165 _target = temp;
166 wlr_log(L_DEBUG, "Isolated name from workspace number: '%s'", _target); 166 wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target);
167 167
168 // Make sure the workspace number doesn't already exist 168 // Make sure the workspace number doesn't already exist
169 if (workspace_by_number(_target)) { 169 if (workspace_by_number(_target)) {
@@ -192,7 +192,9 @@ char *workspace_next_name(const char *output_name) {
192 order = binding->order; 192 order = binding->order;
193 free(target); 193 free(target);
194 target = _target; 194 target = _target;
195 wlr_log(L_DEBUG, "Workspace: Found free name %s", _target); 195 wlr_log(WLR_DEBUG, "Workspace: Found free name %s", _target);
196 } else {
197 free(_target);
196 } 198 }
197 } 199 }
198 free(dup); 200 free(dup);
@@ -203,14 +205,9 @@ char *workspace_next_name(const char *output_name) {
203 // As a fall back, get the current number of active workspaces 205 // As a fall back, get the current number of active workspaces
204 // and return that + 1 for the next workspace's name 206 // and return that + 1 for the next workspace's name
205 int ws_num = root_container.children->length; 207 int ws_num = root_container.children->length;
206 if (ws_num >= 10) { 208 int l = snprintf(NULL, 0, "%d", ws_num);
207 l = 2;
208 } else if (ws_num >= 100) {
209 l = 3;
210 }
211 char *name = malloc(l + 1); 209 char *name = malloc(l + 1);
212 if (!name) { 210 if (!sway_assert(name, "Cloud not allocate workspace name")) {
213 wlr_log(L_ERROR, "Could not allocate workspace name");
214 return NULL; 211 return NULL;
215 } 212 }
216 sprintf(name, "%d", ws_num++); 213 sprintf(name, "%d", ws_num++);
@@ -272,6 +269,9 @@ struct sway_container *workspace_by_name(const char *name) {
272 */ 269 */
273struct sway_container *workspace_output_prev_next_impl( 270struct sway_container *workspace_output_prev_next_impl(
274 struct sway_container *output, bool next) { 271 struct sway_container *output, bool next) {
272 if (!output) {
273 return NULL;
274 }
275 if (!sway_assert(output->type == C_OUTPUT, 275 if (!sway_assert(output->type == C_OUTPUT,
276 "Argument must be an output, is %d", output->type)) { 276 "Argument must be an output, is %d", output->type)) {
277 return NULL; 277 return NULL;
@@ -304,6 +304,9 @@ struct sway_container *workspace_output_prev_next_impl(
304 */ 304 */
305struct sway_container *workspace_prev_next_impl( 305struct sway_container *workspace_prev_next_impl(
306 struct sway_container *workspace, bool next) { 306 struct sway_container *workspace, bool next) {
307 if (!workspace) {
308 return NULL;
309 }
307 if (!sway_assert(workspace->type == C_WORKSPACE, 310 if (!sway_assert(workspace->type == C_WORKSPACE,
308 "Argument must be a workspace, is %d", workspace->type)) { 311 "Argument must be a workspace, is %d", workspace->type)) {
309 return NULL; 312 return NULL;
@@ -386,7 +389,7 @@ bool workspace_switch(struct sway_container *workspace) {
386 free(prev_workspace_name); 389 free(prev_workspace_name);
387 prev_workspace_name = malloc(strlen(active_ws->name) + 1); 390 prev_workspace_name = malloc(strlen(active_ws->name) + 1);
388 if (!prev_workspace_name) { 391 if (!prev_workspace_name) {
389 wlr_log(L_ERROR, "Unable to allocate previous workspace name"); 392 wlr_log(WLR_ERROR, "Unable to allocate previous workspace name");
390 return false; 393 return false;
391 } 394 }
392 strcpy(prev_workspace_name, active_ws->name); 395 strcpy(prev_workspace_name, active_ws->name);
@@ -408,7 +411,7 @@ bool workspace_switch(struct sway_container *workspace) {
408 } 411 }
409 } 412 }
410 413
411 wlr_log(L_DEBUG, "Switching to workspace %p:%s", 414 wlr_log(WLR_DEBUG, "Switching to workspace %p:%s",
412 workspace, workspace->name); 415 workspace, workspace->name);
413 struct sway_container *next = seat_get_focus_inactive(seat, workspace); 416 struct sway_container *next = seat_get_focus_inactive(seat, workspace);
414 if (next == NULL) { 417 if (next == NULL) {
@@ -426,7 +429,7 @@ bool workspace_switch(struct sway_container *workspace) {
426 } 429 }
427 seat_set_focus(seat, next); 430 seat_set_focus(seat, next);
428 struct sway_container *output = container_parent(workspace, C_OUTPUT); 431 struct sway_container *output = container_parent(workspace, C_OUTPUT);
429 arrange_and_commit(output); 432 arrange_windows(output);
430 return true; 433 return true;
431} 434}
432 435
@@ -518,6 +521,16 @@ struct sway_container *workspace_output_get_highest_available(
518 return NULL; 521 return NULL;
519} 522}
520 523
524void workspace_detect_urgent(struct sway_container *workspace) {
525 bool new_urgent = container_has_urgent_child(workspace);
526
527 if (workspace->sway_workspace->urgent != new_urgent) {
528 workspace->sway_workspace->urgent = new_urgent;
529 ipc_event_workspace(NULL, workspace, "urgent");
530 container_damage_whole(workspace);
531 }
532}
533
521struct pid_workspace { 534struct pid_workspace {
522 pid_t pid; 535 pid_t pid;
523 char *workspace; 536 char *workspace;
@@ -540,14 +553,14 @@ struct sway_container *workspace_for_pid(pid_t pid) {
540 struct sway_container *ws = NULL; 553 struct sway_container *ws = NULL;
541 struct pid_workspace *pw = NULL; 554 struct pid_workspace *pw = NULL;
542 555
543 wlr_log(L_DEBUG, "Looking up workspace for pid %d", pid); 556 wlr_log(WLR_DEBUG, "Looking up workspace for pid %d", pid);
544 557
545 do { 558 do {
546 struct pid_workspace *_pw = NULL; 559 struct pid_workspace *_pw = NULL;
547 wl_list_for_each(_pw, &pid_workspaces, link) { 560 wl_list_for_each(_pw, &pid_workspaces, link) {
548 if (pid == _pw->pid) { 561 if (pid == _pw->pid) {
549 pw = _pw; 562 pw = _pw;
550 wlr_log(L_DEBUG, 563 wlr_log(WLR_DEBUG,
551 "found pid_workspace for pid %d, workspace %s", 564 "found pid_workspace for pid %d, workspace %s",
552 pid, pw->workspace); 565 pid, pw->workspace);
553 goto found; 566 goto found;
@@ -561,7 +574,7 @@ found:
561 ws = workspace_by_name(pw->workspace); 574 ws = workspace_by_name(pw->workspace);
562 575
563 if (!ws) { 576 if (!ws) {
564 wlr_log(L_DEBUG, 577 wlr_log(WLR_DEBUG,
565 "Creating workspace %s for pid %d because it disappeared", 578 "Creating workspace %s for pid %d because it disappeared",
566 pw->workspace, pid); 579 pw->workspace, pid);
567 ws = workspace_create(pw->output, pw->workspace); 580 ws = workspace_create(pw->output, pw->workspace);
@@ -582,7 +595,7 @@ static void pw_handle_output_destroy(struct wl_listener *listener, void *data) {
582} 595}
583 596
584void workspace_record_pid(pid_t pid) { 597void workspace_record_pid(pid_t pid) {
585 wlr_log(L_DEBUG, "Recording workspace for process %d", pid); 598 wlr_log(WLR_DEBUG, "Recording workspace for process %d", pid);
586 if (!pid_workspaces.prev && !pid_workspaces.next) { 599 if (!pid_workspaces.prev && !pid_workspaces.next) {
587 wl_list_init(&pid_workspaces); 600 wl_list_init(&pid_workspaces);
588 } 601 }
@@ -594,12 +607,12 @@ void workspace_record_pid(pid_t pid) {
594 ws = container_parent(ws, C_WORKSPACE); 607 ws = container_parent(ws, C_WORKSPACE);
595 } 608 }
596 if (!ws) { 609 if (!ws) {
597 wlr_log(L_DEBUG, "Bailing out, no workspace"); 610 wlr_log(WLR_DEBUG, "Bailing out, no workspace");
598 return; 611 return;
599 } 612 }
600 struct sway_container *output = ws->parent; 613 struct sway_container *output = ws->parent;
601 if (!output) { 614 if (!output) {
602 wlr_log(L_DEBUG, "Bailing out, no output"); 615 wlr_log(WLR_DEBUG, "Bailing out, no output");
603 return; 616 return;
604 } 617 }
605 618