aboutsummaryrefslogtreecommitdiffstats
path: root/sway/handlers.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/handlers.c')
-rw-r--r--sway/handlers.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index 317b03a8..9efd3ffc 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -7,7 +7,9 @@
7#include <wlc/wlc-render.h> 7#include <wlc/wlc-render.h>
8#include <wlc/wlc-wayland.h> 8#include <wlc/wlc-wayland.h>
9#include <ctype.h> 9#include <ctype.h>
10#include <unistd.h>
10 11
12#include "util.h"
11#include "handlers.h" 13#include "handlers.h"
12#include "border.h" 14#include "border.h"
13#include "log.h" 15#include "log.h"
@@ -180,6 +182,12 @@ static bool handle_view_created(wlc_handle handle) {
180 wlc_handle parent = wlc_view_get_parent(handle); 182 wlc_handle parent = wlc_view_get_parent(handle);
181 swayc_t *focused = NULL; 183 swayc_t *focused = NULL;
182 swayc_t *newview = NULL; 184 swayc_t *newview = NULL;
185 swayc_t *current_ws = swayc_active_workspace();
186 bool return_to_workspace = false;
187
188 if (current_ws) {
189 sway_log(L_DEBUG, "current workspace is %s", current_ws->name);
190 }
183 191
184 // Get parent container, to add view in 192 // Get parent container, to add view in
185 if (parent) { 193 if (parent) {
@@ -209,16 +217,22 @@ static bool handle_view_created(wlc_handle handle) {
209 if (pid) { 217 if (pid) {
210 sway_log(L_DEBUG, "found pid %d for client", pid); 218 sway_log(L_DEBUG, "found pid %d for client", pid);
211 int i; 219 int i;
212 for (i = 0; i < config->pid_workspaces->length; i++) { 220 do {
213 pw = config->pid_workspaces->items[i]; 221 for (i = 0; i < config->pid_workspaces->length; i++) {
214 pid_t *pw_pid = pw->pid; 222 pw = config->pid_workspaces->items[i];
215 sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i); 223 pid_t *pw_pid = pw->pid;
216 if (pid == *pw_pid) { 224 sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i);
217 sway_log(L_DEBUG, "found pid_workspace for pid, %d %s", pid, pw->workspace); 225 if (pid == *pw_pid) {
218 break; 226 sway_log(L_DEBUG, "found pid_workspace for pid, %d %s", pid, pw->workspace);
227 break; // out of for loop
228 }
229 pw = NULL;
219 } 230 }
220 pw = NULL; 231 if (pw) {
221 } 232 break; // out of do-while loop
233 }
234 pid = get_parent_pid(pid);
235 } while (pid > -1 && pid != getpid());
222 236
223 swayc_t *ws = NULL; 237 swayc_t *ws = NULL;
224 238
@@ -233,6 +247,10 @@ static bool handle_view_created(wlc_handle handle) {
233 if (ws) { 247 if (ws) {
234 sway_log(L_DEBUG, "workspace exists, name is %s", ws->name); 248 sway_log(L_DEBUG, "workspace exists, name is %s", ws->name);
235 focused = ws; 249 focused = ws;
250
251 if (current_ws && (strcmp(current_ws->name, ws->name) != 0)) {
252 return_to_workspace = true;
253 }
236 } 254 }
237 255
238 list_del(config->pid_workspaces, i); 256 list_del(config->pid_workspaces, i);
@@ -240,7 +258,6 @@ static bool handle_view_created(wlc_handle handle) {
240 } 258 }
241 259
242 free_pid_workspace(pw); 260 free_pid_workspace(pw);
243 // free(&pid);
244 261
245 if (!focused || focused->type == C_OUTPUT) { 262 if (!focused || focused->type == C_OUTPUT) {
246 focused = get_focused_container(&root_container); 263 focused = get_focused_container(&root_container);
@@ -330,6 +347,12 @@ static bool handle_view_created(wlc_handle handle) {
330 list_add(output->unmanaged, h); 347 list_add(output->unmanaged, h);
331 } 348 }
332 wlc_view_set_mask(handle, VISIBLE); 349 wlc_view_set_mask(handle, VISIBLE);
350
351 if (return_to_workspace && current_ws) {
352 sway_log(L_DEBUG, "return_to_workspace && current_ws");
353 workspace_switch(current_ws);
354 set_focused_container(current_ws->focused);
355 }
333 return true; 356 return true;
334} 357}
335 358