aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin+git@gmail.com>2016-06-11 09:20:09 -0500
committerLibravatar Zandr Martin <zandrmartin+git@gmail.com>2016-06-11 09:20:09 -0500
commitbeaa03344eda931274b75275bfc2d622e6875956 (patch)
tree166d43eb515eeb16e6fe369e7193ba268fa94406
parentsemi-working (only non-client/server wayland apps) (diff)
downloadsway-beaa03344eda931274b75275bfc2d622e6875956.tar.gz
sway-beaa03344eda931274b75275bfc2d622e6875956.tar.zst
sway-beaa03344eda931274b75275bfc2d622e6875956.zip
clean up pid/workspace stuff
-rw-r--r--include/workspace.h2
-rw-r--r--sway/handlers.c78
-rw-r--r--sway/workspace.c53
3 files changed, 68 insertions, 65 deletions
diff --git a/include/workspace.h b/include/workspace.h
index 6911e3d4..c268fafa 100644
--- a/include/workspace.h
+++ b/include/workspace.h
@@ -2,6 +2,7 @@
2#define _SWAY_WORKSPACE_H 2#define _SWAY_WORKSPACE_H
3 3
4#include <wlc/wlc.h> 4#include <wlc/wlc.h>
5#include <unistd.h>
5#include "list.h" 6#include "list.h"
6#include "layout.h" 7#include "layout.h"
7 8
@@ -16,5 +17,6 @@ swayc_t *workspace_output_next();
16swayc_t *workspace_next(); 17swayc_t *workspace_next();
17swayc_t *workspace_output_prev(); 18swayc_t *workspace_output_prev();
18swayc_t *workspace_prev(); 19swayc_t *workspace_prev();
20swayc_t *workspace_for_pid(pid_t pid);
19 21
20#endif 22#endif
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 }
diff --git a/sway/workspace.c b/sway/workspace.c
index 82573d2e..0c5c70a3 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -5,6 +5,7 @@
5#include <wlc/wlc.h> 5#include <wlc/wlc.h>
6#include <string.h> 6#include <string.h>
7#include <strings.h> 7#include <strings.h>
8#include <sys/types.h>
8#include "ipc-server.h" 9#include "ipc-server.h"
9#include "workspace.h" 10#include "workspace.h"
10#include "layout.h" 11#include "layout.h"
@@ -309,3 +310,55 @@ bool workspace_switch(swayc_t *workspace) {
309 arrange_windows(output, -1, -1); 310 arrange_windows(output, -1, -1);
310 return true; 311 return true;
311} 312}
313
314swayc_t *workspace_for_pid(pid_t pid) {
315 int i;
316 swayc_t *ws = NULL;
317 struct pid_workspace *pw = NULL;
318
319 sway_log(L_DEBUG, "looking for workspace for pid %d", pid);
320
321 // leaving this here as it's useful for debugging
322 // sway_log(L_DEBUG, "all pid_workspaces");
323 // for (int k = 0; k < config->pid_workspaces->length; k++) {
324 // pw = config->pid_workspaces->items[k];
325 // sway_log(L_DEBUG, "pid %d workspace %s", *pw->pid, pw->workspace);
326 // }
327
328 do {
329 for (i = 0; i < config->pid_workspaces->length; i++) {
330 pw = config->pid_workspaces->items[i];
331 pid_t *pw_pid = pw->pid;
332
333 if (pid == *pw_pid) {
334 sway_log(L_DEBUG, "found pid_workspace for pid %d, workspace %s", pid, pw->workspace);
335 break; // out of for loop
336 }
337
338 pw = NULL;
339 }
340
341 if (pw) {
342 break; // out of do-while loop
343 }
344
345 pid = get_parent_pid(pid);
346 // no sense in looking for matches for pid 0.
347 // also, if pid == getpid(), that is the compositor's
348 // pid, which definitely isn't helpful
349 } while (pid > 0 && pid != getpid());
350
351 if (pw) {
352 ws = workspace_by_name(pw->workspace);
353
354 if (!ws) {
355 sway_log(L_DEBUG, "creating workspace %s because it disappeared", pw->workspace);
356 ws = workspace_create(pw->workspace);
357 }
358
359 list_del(config->pid_workspaces, i);
360 }
361
362 free_pid_workspace(pw);
363 return ws;
364}