diff options
Diffstat (limited to 'sway/handlers.c')
-rw-r--r-- | sway/handlers.c | 78 |
1 files changed, 13 insertions, 65 deletions
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 @@ | |||
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> | ||
11 | 10 | ||
12 | #include "util.h" | ||
13 | #include "handlers.h" | 11 | #include "handlers.h" |
14 | #include "border.h" | 12 | #include "border.h" |
15 | #include "log.h" | 13 | #include "log.h" |
@@ -184,81 +182,30 @@ static bool handle_view_created(wlc_handle handle) { | |||
184 | swayc_t *newview = NULL; | 182 | swayc_t *newview = NULL; |
185 | swayc_t *current_ws = swayc_active_workspace(); | 183 | swayc_t *current_ws = swayc_active_workspace(); |
186 | bool return_to_workspace = false; | 184 | bool return_to_workspace = false; |
187 | 185 | struct wl_client *client = wlc_view_get_wl_client(handle); | |
188 | if (current_ws) { | 186 | pid_t pid; |
189 | sway_log(L_DEBUG, "current workspace is %s", current_ws->name); | ||
190 | } | ||
191 | 187 | ||
192 | // Get parent container, to add view in | 188 | // Get parent container, to add view in |
193 | if (parent) { | 189 | if (parent) { |
194 | focused = swayc_by_handle(parent); | 190 | focused = swayc_by_handle(parent); |
195 | } | 191 | } |
196 | 192 | ||
197 | // TODO: test with wayland apps (gnome terminal or corebird) | ||
198 | |||
199 | // try to match this up to a pid_workspace | ||
200 | struct wl_client *client = wlc_view_get_wl_client(handle); | ||
201 | pid_t pid; | ||
202 | struct pid_workspace *pw = NULL; | ||
203 | |||
204 | sway_log(L_DEBUG, "checking pid workspaces, handle is %lu", handle); | ||
205 | |||
206 | if (client) { | 193 | if (client) { |
207 | sway_log(L_DEBUG, "found client"); | 194 | // below only works on wayland windows. need a wlc |
195 | // api that will work for both wayland and x. | ||
208 | wl_client_get_credentials(client, &pid, NULL, NULL); | 196 | wl_client_get_credentials(client, &pid, NULL, NULL); |
209 | } | ||
210 | 197 | ||
211 | sway_log(L_DEBUG, "all pid_workspaces"); | 198 | if (pid) { |
212 | for (int k = 0; k < config->pid_workspaces->length; k++) { | 199 | // using newview as a temp storage location here, |
213 | pw = config->pid_workspaces->items[k]; | 200 | // rather than adding yet another workspace var |
214 | sway_log(L_DEBUG, "pid %d workspace %s", *pw->pid, pw->workspace); | 201 | if ((newview = workspace_for_pid(pid))) { |
215 | } | 202 | focused = newview; |
216 | 203 | newview = NULL; | |
217 | if (pid) { | 204 | return_to_workspace = true; |
218 | sway_log(L_DEBUG, "found pid %d for client", pid); | ||
219 | int i; | ||
220 | do { | ||
221 | for (i = 0; i < config->pid_workspaces->length; i++) { | ||
222 | pw = config->pid_workspaces->items[i]; | ||
223 | pid_t *pw_pid = pw->pid; | ||
224 | sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i); | ||
225 | if (pid == *pw_pid) { | ||
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; | ||
230 | } | ||
231 | if (pw) { | ||
232 | break; // out of do-while loop | ||
233 | } | ||
234 | pid = get_parent_pid(pid); | ||
235 | } while (pid > -1 && pid != getpid()); | ||
236 | |||
237 | swayc_t *ws = NULL; | ||
238 | |||
239 | if (pw) { | ||
240 | ws = workspace_by_name(pw->workspace); | ||
241 | |||
242 | if (!ws) { | ||
243 | sway_log(L_DEBUG, "creating workspace %s because it disappeared", pw->workspace); | ||
244 | ws = workspace_create(pw->workspace); | ||
245 | } | 205 | } |
246 | |||
247 | if (ws) { | ||
248 | sway_log(L_DEBUG, "workspace exists, name is %s", ws->name); | ||
249 | focused = ws; | ||
250 | |||
251 | if (current_ws && (strcmp(current_ws->name, ws->name) != 0)) { | ||
252 | return_to_workspace = true; | ||
253 | } | ||
254 | } | ||
255 | |||
256 | list_del(config->pid_workspaces, i); | ||
257 | } | 206 | } |
258 | } | 207 | } |
259 | 208 | ||
260 | free_pid_workspace(pw); | ||
261 | |||
262 | if (!focused || focused->type == C_OUTPUT) { | 209 | if (!focused || focused->type == C_OUTPUT) { |
263 | focused = get_focused_container(&root_container); | 210 | focused = get_focused_container(&root_container); |
264 | // Move focus from floating view | 211 | // Move focus from floating view |
@@ -349,7 +296,8 @@ static bool handle_view_created(wlc_handle handle) { | |||
349 | wlc_view_set_mask(handle, VISIBLE); | 296 | wlc_view_set_mask(handle, VISIBLE); |
350 | 297 | ||
351 | if (return_to_workspace && current_ws) { | 298 | if (return_to_workspace && current_ws) { |
352 | sway_log(L_DEBUG, "return_to_workspace && current_ws"); | 299 | // we were on one workspace, switched to another to add this view, |
300 | // now let's return to where we were | ||
353 | workspace_switch(current_ws); | 301 | workspace_switch(current_ws); |
354 | set_focused_container(current_ws->focused); | 302 | set_focused_container(current_ws->focused); |
355 | } | 303 | } |