From 0f1859ed25741927117b31cdd3ef2560f0327688 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Mon, 6 Jun 2016 06:58:53 -0500 Subject: messy, unfinished version --- sway/handlers.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index f8dd9f4d..317b03a8 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -185,6 +185,63 @@ static bool handle_view_created(wlc_handle handle) { if (parent) { focused = swayc_by_handle(parent); } + + // TODO: test with wayland apps (gnome terminal or corebird) + + // try to match this up to a pid_workspace + struct wl_client *client = wlc_view_get_wl_client(handle); + pid_t pid; + struct pid_workspace *pw = NULL; + + sway_log(L_DEBUG, "checking pid workspaces, handle is %lu", handle); + + if (client) { + sway_log(L_DEBUG, "found client"); + wl_client_get_credentials(client, &pid, NULL, NULL); + } + + sway_log(L_DEBUG, "all pid_workspaces"); + for (int k = 0; k < config->pid_workspaces->length; k++) { + pw = config->pid_workspaces->items[k]; + sway_log(L_DEBUG, "pid %d workspace %s", *pw->pid, pw->workspace); + } + + if (pid) { + sway_log(L_DEBUG, "found pid %d for client", pid); + int i; + for (i = 0; i < config->pid_workspaces->length; i++) { + pw = config->pid_workspaces->items[i]; + pid_t *pw_pid = pw->pid; + sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i); + if (pid == *pw_pid) { + sway_log(L_DEBUG, "found pid_workspace for pid, %d %s", pid, pw->workspace); + break; + } + pw = NULL; + } + + swayc_t *ws = NULL; + + if (pw) { + ws = workspace_by_name(pw->workspace); + + if (!ws) { + sway_log(L_DEBUG, "creating workspace %s because it disappeared", pw->workspace); + ws = workspace_create(pw->workspace); + } + + if (ws) { + sway_log(L_DEBUG, "workspace exists, name is %s", ws->name); + focused = ws; + } + + list_del(config->pid_workspaces, i); + } + } + + free_pid_workspace(pw); + // free(&pid); + if (!focused || focused->type == C_OUTPUT) { focused = get_focused_container(&root_container); // Move focus from floating view @@ -220,7 +277,7 @@ static bool handle_view_created(wlc_handle handle) { // Dmenu keeps viewfocus, but others with this flag don't, for now simulate // dmenu case WLC_BIT_OVERRIDE_REDIRECT: -// locked_view_focus = true; + // locked_view_focus = true; wlc_view_focus(handle); wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); wlc_view_bring_to_front(handle); -- cgit v1.2.3 From 03d79b41c71f091f61f4712963a3760fd24fdb62 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Fri, 10 Jun 2016 06:08:59 -0500 Subject: semi-working (only non-client/server wayland apps) --- sway/handlers.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'sway/handlers.c') 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 @@ #include #include #include +#include +#include "util.h" #include "handlers.h" #include "border.h" #include "log.h" @@ -180,6 +182,12 @@ static bool handle_view_created(wlc_handle handle) { wlc_handle parent = wlc_view_get_parent(handle); swayc_t *focused = NULL; swayc_t *newview = NULL; + swayc_t *current_ws = swayc_active_workspace(); + bool return_to_workspace = false; + + if (current_ws) { + sway_log(L_DEBUG, "current workspace is %s", current_ws->name); + } // Get parent container, to add view in if (parent) { @@ -209,16 +217,22 @@ static bool handle_view_created(wlc_handle handle) { if (pid) { sway_log(L_DEBUG, "found pid %d for client", pid); int i; - for (i = 0; i < config->pid_workspaces->length; i++) { - pw = config->pid_workspaces->items[i]; - pid_t *pw_pid = pw->pid; - sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i); - if (pid == *pw_pid) { - sway_log(L_DEBUG, "found pid_workspace for pid, %d %s", pid, pw->workspace); - break; + do { + for (i = 0; i < config->pid_workspaces->length; i++) { + pw = config->pid_workspaces->items[i]; + pid_t *pw_pid = pw->pid; + sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i); + if (pid == *pw_pid) { + sway_log(L_DEBUG, "found pid_workspace for pid, %d %s", pid, pw->workspace); + break; // out of for loop + } + pw = NULL; } - pw = NULL; - } + if (pw) { + break; // out of do-while loop + } + pid = get_parent_pid(pid); + } while (pid > -1 && pid != getpid()); swayc_t *ws = NULL; @@ -233,6 +247,10 @@ static bool handle_view_created(wlc_handle handle) { if (ws) { sway_log(L_DEBUG, "workspace exists, name is %s", ws->name); focused = ws; + + if (current_ws && (strcmp(current_ws->name, ws->name) != 0)) { + return_to_workspace = true; + } } list_del(config->pid_workspaces, i); @@ -240,7 +258,6 @@ static bool handle_view_created(wlc_handle handle) { } free_pid_workspace(pw); - // free(&pid); if (!focused || focused->type == C_OUTPUT) { focused = get_focused_container(&root_container); @@ -330,6 +347,12 @@ static bool handle_view_created(wlc_handle handle) { list_add(output->unmanaged, h); } wlc_view_set_mask(handle, VISIBLE); + + if (return_to_workspace && current_ws) { + sway_log(L_DEBUG, "return_to_workspace && current_ws"); + workspace_switch(current_ws); + set_focused_container(current_ws->focused); + } return true; } -- cgit v1.2.3 From beaa03344eda931274b75275bfc2d622e6875956 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Sat, 11 Jun 2016 09:20:09 -0500 Subject: clean up pid/workspace stuff --- sway/handlers.c | 78 ++++++++++----------------------------------------------- 1 file changed, 13 insertions(+), 65 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 9efd3ffc..b38f05a6 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -7,9 +7,7 @@ #include #include #include -#include -#include "util.h" #include "handlers.h" #include "border.h" #include "log.h" @@ -184,81 +182,30 @@ static bool handle_view_created(wlc_handle handle) { swayc_t *newview = NULL; swayc_t *current_ws = swayc_active_workspace(); bool return_to_workspace = false; - - if (current_ws) { - sway_log(L_DEBUG, "current workspace is %s", current_ws->name); - } + struct wl_client *client = wlc_view_get_wl_client(handle); + pid_t pid; // Get parent container, to add view in if (parent) { focused = swayc_by_handle(parent); } - // TODO: test with wayland apps (gnome terminal or corebird) - - // try to match this up to a pid_workspace - struct wl_client *client = wlc_view_get_wl_client(handle); - pid_t pid; - struct pid_workspace *pw = NULL; - - sway_log(L_DEBUG, "checking pid workspaces, handle is %lu", handle); - if (client) { - sway_log(L_DEBUG, "found client"); + // below only works on wayland windows. need a wlc + // api that will work for both wayland and x. wl_client_get_credentials(client, &pid, NULL, NULL); - } - sway_log(L_DEBUG, "all pid_workspaces"); - for (int k = 0; k < config->pid_workspaces->length; k++) { - pw = config->pid_workspaces->items[k]; - sway_log(L_DEBUG, "pid %d workspace %s", *pw->pid, pw->workspace); - } - - if (pid) { - sway_log(L_DEBUG, "found pid %d for client", pid); - int i; - do { - for (i = 0; i < config->pid_workspaces->length; i++) { - pw = config->pid_workspaces->items[i]; - pid_t *pw_pid = pw->pid; - sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i); - if (pid == *pw_pid) { - sway_log(L_DEBUG, "found pid_workspace for pid, %d %s", pid, pw->workspace); - break; // out of for loop - } - pw = NULL; - } - if (pw) { - break; // out of do-while loop - } - pid = get_parent_pid(pid); - } while (pid > -1 && pid != getpid()); - - swayc_t *ws = NULL; - - if (pw) { - ws = workspace_by_name(pw->workspace); - - if (!ws) { - sway_log(L_DEBUG, "creating workspace %s because it disappeared", pw->workspace); - ws = workspace_create(pw->workspace); + if (pid) { + // using newview as a temp storage location here, + // rather than adding yet another workspace var + if ((newview = workspace_for_pid(pid))) { + focused = newview; + newview = NULL; + return_to_workspace = true; } - - if (ws) { - sway_log(L_DEBUG, "workspace exists, name is %s", ws->name); - focused = ws; - - if (current_ws && (strcmp(current_ws->name, ws->name) != 0)) { - return_to_workspace = true; - } - } - - list_del(config->pid_workspaces, i); } } - free_pid_workspace(pw); - if (!focused || focused->type == C_OUTPUT) { focused = get_focused_container(&root_container); // Move focus from floating view @@ -349,7 +296,8 @@ static bool handle_view_created(wlc_handle handle) { wlc_view_set_mask(handle, VISIBLE); if (return_to_workspace && current_ws) { - sway_log(L_DEBUG, "return_to_workspace && current_ws"); + // we were on one workspace, switched to another to add this view, + // now let's return to where we were workspace_switch(current_ws); set_focused_container(current_ws->focused); } -- cgit v1.2.3