aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c13
-rw-r--r--sway/config.c15
-rw-r--r--sway/handlers.c30
-rw-r--r--sway/workspace.c53
4 files changed, 107 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 07e7e53d..3a6b2af5 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -549,12 +549,19 @@ static struct cmd_results *cmd_exec_always(int argc, char **argv) {
close(fd[0]);
// cleanup child process
wait(0);
- if (*child > 0) {
- sway_log(L_DEBUG, "Child process created with pid %d", *child);
+ swayc_t *ws = swayc_active_workspace();
+ if (*child > 0 && ws) {
+ sway_log(L_DEBUG, "Child process created with pid %d for workspace %s", *child, ws->name);
+ struct pid_workspace *pw = malloc(sizeof(struct pid_workspace));
+ pw->pid = child;
+ pw->workspace = strdup(ws->name);
+ list_add(config->pid_workspaces, pw);
// TODO: keep track of this pid and open the corresponding view on the current workspace
// blocked pending feature in wlc
+ } else {
+ free(child);
}
- free(child);
+
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/config.c b/sway/config.c
index 7530e530..07b1f2f7 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -89,6 +89,15 @@ static void free_workspace_output(struct workspace_output *wo) {
free(wo);
}
+void free_pid_workspace(struct pid_workspace *pw) {
+ if (!pw) {
+ return;
+ }
+ free(pw->pid);
+ free(pw->workspace);
+ free(pw);
+}
+
void free_config(struct sway_config *config) {
int i;
for (i = 0; i < config->symbols->length; ++i) {
@@ -113,6 +122,11 @@ void free_config(struct sway_config *config) {
}
list_free(config->workspace_outputs);
+ for (i = 0; i < config->pid_workspaces->length; ++i) {
+ free_pid_workspace(config->pid_workspaces->items[i]);
+ }
+ list_free(config->pid_workspaces);
+
for (i = 0; i < config->criteria->length; ++i) {
free_criteria(config->criteria->items[i]);
}
@@ -148,6 +162,7 @@ static void config_defaults(struct sway_config *config) {
config->modes = create_list();
config->bars = create_list();
config->workspace_outputs = create_list();
+ config->pid_workspaces = create_list();
config->criteria = create_list();
config->input_configs = create_list();
config->output_configs = create_list();
diff --git a/sway/handlers.c b/sway/handlers.c
index f8dd9f4d..b38f05a6 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -180,11 +180,32 @@ 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;
+ 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);
}
+
+ if (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);
+
+ 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 (!focused || focused->type == C_OUTPUT) {
focused = get_focused_container(&root_container);
// Move focus from floating view
@@ -220,7 +241,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);
@@ -273,6 +294,13 @@ 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) {
+ // 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);
+ }
return true;
}
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 @@
#include <wlc/wlc.h>
#include <string.h>
#include <strings.h>
+#include <sys/types.h>
#include "ipc-server.h"
#include "workspace.h"
#include "layout.h"
@@ -309,3 +310,55 @@ bool workspace_switch(swayc_t *workspace) {
arrange_windows(output, -1, -1);
return true;
}
+
+swayc_t *workspace_for_pid(pid_t pid) {
+ int i;
+ swayc_t *ws = NULL;
+ struct pid_workspace *pw = NULL;
+
+ sway_log(L_DEBUG, "looking for workspace for pid %d", pid);
+
+ // leaving this here as it's useful for debugging
+ // 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);
+ // }
+
+ do {
+ for (i = 0; i < config->pid_workspaces->length; i++) {
+ pw = config->pid_workspaces->items[i];
+ pid_t *pw_pid = pw->pid;
+
+ if (pid == *pw_pid) {
+ sway_log(L_DEBUG, "found pid_workspace for pid %d, workspace %s", pid, pw->workspace);
+ break; // out of for loop
+ }
+
+ pw = NULL;
+ }
+
+ if (pw) {
+ break; // out of do-while loop
+ }
+
+ pid = get_parent_pid(pid);
+ // no sense in looking for matches for pid 0.
+ // also, if pid == getpid(), that is the compositor's
+ // pid, which definitely isn't helpful
+ } while (pid > 0 && pid != getpid());
+
+ 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);
+ }
+
+ list_del(config->pid_workspaces, i);
+ }
+
+ free_pid_workspace(pw);
+ return ws;
+}