aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin+git@gmail.com>2016-06-06 06:58:53 -0500
committerLibravatar Zandr Martin <zandrmartin+git@gmail.com>2016-06-06 06:58:53 -0500
commit0f1859ed25741927117b31cdd3ef2560f0327688 (patch)
treeb6c39b0757bb538e70f65dae46e41a298161cff3
parentdocument `assign` command (diff)
downloadsway-0f1859ed25741927117b31cdd3ef2560f0327688.tar.gz
sway-0f1859ed25741927117b31cdd3ef2560f0327688.tar.zst
sway-0f1859ed25741927117b31cdd3ef2560f0327688.zip
messy, unfinished version
-rw-r--r--include/config.h8
-rw-r--r--sway/commands.c13
-rw-r--r--sway/config.c15
-rw-r--r--sway/handlers.c59
4 files changed, 91 insertions, 4 deletions
diff --git a/include/config.h b/include/config.h
index d591daf2..35797ac2 100644
--- a/include/config.h
+++ b/include/config.h
@@ -92,6 +92,13 @@ struct workspace_output {
92 char *workspace; 92 char *workspace;
93}; 93};
94 94
95struct pid_workspace {
96 pid_t *pid;
97 char *workspace;
98};
99
100void free_pid_workspace(struct pid_workspace *pw);
101
95struct bar_config { 102struct bar_config {
96 /** 103 /**
97 * One of "dock", "hide", "invisible" 104 * One of "dock", "hide", "invisible"
@@ -175,6 +182,7 @@ struct sway_config {
175 list_t *bars; 182 list_t *bars;
176 list_t *cmd_queue; 183 list_t *cmd_queue;
177 list_t *workspace_outputs; 184 list_t *workspace_outputs;
185 list_t *pid_workspaces;
178 list_t *output_configs; 186 list_t *output_configs;
179 list_t *input_configs; 187 list_t *input_configs;
180 list_t *criteria; 188 list_t *criteria;
diff --git a/sway/commands.c b/sway/commands.c
index 83a9e7e9..08920c1c 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -549,12 +549,19 @@ static struct cmd_results *cmd_exec_always(int argc, char **argv) {
549 close(fd[0]); 549 close(fd[0]);
550 // cleanup child process 550 // cleanup child process
551 wait(0); 551 wait(0);
552 if (*child > 0) { 552 swayc_t *ws = swayc_active_workspace();
553 sway_log(L_DEBUG, "Child process created with pid %d", *child); 553 if (*child > 0 && ws) {
554 sway_log(L_DEBUG, "Child process created with pid %d for workspace %s", *child, ws->name);
555 struct pid_workspace *pw = malloc(sizeof(struct pid_workspace));
556 pw->pid = child;
557 pw->workspace = strdup(ws->name);
558 list_add(config->pid_workspaces, pw);
554 // TODO: keep track of this pid and open the corresponding view on the current workspace 559 // TODO: keep track of this pid and open the corresponding view on the current workspace
555 // blocked pending feature in wlc 560 // blocked pending feature in wlc
561 } else {
562 free(child);
556 } 563 }
557 free(child); 564
558 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 565 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
559} 566}
560 567
diff --git a/sway/config.c b/sway/config.c
index 15108123..321534ed 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -89,6 +89,15 @@ static void free_workspace_output(struct workspace_output *wo) {
89 free(wo); 89 free(wo);
90} 90}
91 91
92void free_pid_workspace(struct pid_workspace *pw) {
93 if (!pw) {
94 return;
95 }
96 free(pw->pid);
97 free(pw->workspace);
98 free(pw);
99}
100
92void free_config(struct sway_config *config) { 101void free_config(struct sway_config *config) {
93 int i; 102 int i;
94 for (i = 0; i < config->symbols->length; ++i) { 103 for (i = 0; i < config->symbols->length; ++i) {
@@ -113,6 +122,11 @@ void free_config(struct sway_config *config) {
113 } 122 }
114 list_free(config->workspace_outputs); 123 list_free(config->workspace_outputs);
115 124
125 for (i = 0; i < config->pid_workspaces->length; ++i) {
126 free_pid_workspace(config->pid_workspaces->items[i]);
127 }
128 list_free(config->pid_workspaces);
129
116 for (i = 0; i < config->criteria->length; ++i) { 130 for (i = 0; i < config->criteria->length; ++i) {
117 free_criteria(config->criteria->items[i]); 131 free_criteria(config->criteria->items[i]);
118 } 132 }
@@ -148,6 +162,7 @@ static void config_defaults(struct sway_config *config) {
148 config->modes = create_list(); 162 config->modes = create_list();
149 config->bars = create_list(); 163 config->bars = create_list();
150 config->workspace_outputs = create_list(); 164 config->workspace_outputs = create_list();
165 config->pid_workspaces = create_list();
151 config->criteria = create_list(); 166 config->criteria = create_list();
152 config->input_configs = create_list(); 167 config->input_configs = create_list();
153 config->output_configs = create_list(); 168 config->output_configs = create_list();
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) {
185 if (parent) { 185 if (parent) {
186 focused = swayc_by_handle(parent); 186 focused = swayc_by_handle(parent);
187 } 187 }
188
189 // TODO: test with wayland apps (gnome terminal or corebird)
190
191 // try to match this up to a pid_workspace
192 struct wl_client *client = wlc_view_get_wl_client(handle);
193 pid_t pid;
194 struct pid_workspace *pw = NULL;
195
196 sway_log(L_DEBUG, "checking pid workspaces, handle is %lu", handle);
197
198 if (client) {
199 sway_log(L_DEBUG, "found client");
200 wl_client_get_credentials(client, &pid, NULL, NULL);
201 }
202
203 sway_log(L_DEBUG, "all pid_workspaces");
204 for (int k = 0; k < config->pid_workspaces->length; k++) {
205 pw = config->pid_workspaces->items[k];
206 sway_log(L_DEBUG, "pid %d workspace %s", *pw->pid, pw->workspace);
207 }
208
209 if (pid) {
210 sway_log(L_DEBUG, "found pid %d for client", pid);
211 int i;
212 for (i = 0; i < config->pid_workspaces->length; i++) {
213 pw = config->pid_workspaces->items[i];
214 pid_t *pw_pid = pw->pid;
215 sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i);
216 if (pid == *pw_pid) {
217 sway_log(L_DEBUG, "found pid_workspace for pid, %d %s", pid, pw->workspace);
218 break;
219 }
220 pw = NULL;
221 }
222
223 swayc_t *ws = NULL;
224
225 if (pw) {
226 ws = workspace_by_name(pw->workspace);
227
228 if (!ws) {
229 sway_log(L_DEBUG, "creating workspace %s because it disappeared", pw->workspace);
230 ws = workspace_create(pw->workspace);
231 }
232
233 if (ws) {
234 sway_log(L_DEBUG, "workspace exists, name is %s", ws->name);
235 focused = ws;
236 }
237
238 list_del(config->pid_workspaces, i);
239 }
240 }
241
242 free_pid_workspace(pw);
243 // free(&pid);
244
188 if (!focused || focused->type == C_OUTPUT) { 245 if (!focused || focused->type == C_OUTPUT) {
189 focused = get_focused_container(&root_container); 246 focused = get_focused_container(&root_container);
190 // Move focus from floating view 247 // Move focus from floating view
@@ -220,7 +277,7 @@ static bool handle_view_created(wlc_handle handle) {
220 // Dmenu keeps viewfocus, but others with this flag don't, for now simulate 277 // Dmenu keeps viewfocus, but others with this flag don't, for now simulate
221 // dmenu 278 // dmenu
222 case WLC_BIT_OVERRIDE_REDIRECT: 279 case WLC_BIT_OVERRIDE_REDIRECT:
223// locked_view_focus = true; 280 // locked_view_focus = true;
224 wlc_view_focus(handle); 281 wlc_view_focus(handle);
225 wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); 282 wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true);
226 wlc_view_bring_to_front(handle); 283 wlc_view_bring_to_front(handle);