diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-01-22 01:02:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-22 01:02:48 -0500 |
commit | f493fb526d3aabb4e756409a3a69e304759f4201 (patch) | |
tree | 239b2c3d5212a5663eb3c0868543f505b03d3953 /sway/tree | |
parent | swaybar: fix setting floating watcher slots (diff) | |
parent | Removed unused wlroots dependency for sway(bg|bar|msg|nag) (diff) | |
download | sway-f493fb526d3aabb4e756409a3a69e304759f4201.tar.gz sway-f493fb526d3aabb4e756409a3a69e304759f4201.tar.zst sway-f493fb526d3aabb4e756409a3a69e304759f4201.zip |
Merge pull request #3485 from mstoeckl/minimize-deps
Remove wlroots dependency for sway(bar|bg|msg|nag)
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/output.c | 16 | ||||
-rw-r--r-- | sway/tree/root.c | 35 |
2 files changed, 51 insertions, 0 deletions
diff --git a/sway/tree/output.c b/sway/tree/output.c index 7fbeeebd..50a2c535 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <assert.h> | ||
2 | #include <ctype.h> | 3 | #include <ctype.h> |
3 | #include <string.h> | 4 | #include <string.h> |
4 | #include <strings.h> | 5 | #include <strings.h> |
@@ -12,6 +13,21 @@ | |||
12 | #include "log.h" | 13 | #include "log.h" |
13 | #include "util.h" | 14 | #include "util.h" |
14 | 15 | ||
16 | enum wlr_direction opposite_direction(enum wlr_direction d) { | ||
17 | switch (d) { | ||
18 | case WLR_DIRECTION_UP: | ||
19 | return WLR_DIRECTION_DOWN; | ||
20 | case WLR_DIRECTION_DOWN: | ||
21 | return WLR_DIRECTION_UP; | ||
22 | case WLR_DIRECTION_RIGHT: | ||
23 | return WLR_DIRECTION_LEFT; | ||
24 | case WLR_DIRECTION_LEFT: | ||
25 | return WLR_DIRECTION_RIGHT; | ||
26 | } | ||
27 | assert(false); | ||
28 | return 0; | ||
29 | } | ||
30 | |||
15 | static void restore_workspaces(struct sway_output *output) { | 31 | static void restore_workspaces(struct sway_output *output) { |
16 | // Workspace output priority | 32 | // Workspace output priority |
17 | for (int i = 0; i < root->outputs->length; i++) { | 33 | for (int i = 0; i < root->outputs->length; i++) { |
diff --git a/sway/tree/root.c b/sway/tree/root.c index 08ce7942..d4b97be3 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c | |||
@@ -169,6 +169,41 @@ struct pid_workspace { | |||
169 | 169 | ||
170 | static struct wl_list pid_workspaces; | 170 | static struct wl_list pid_workspaces; |
171 | 171 | ||
172 | /** | ||
173 | * Get the pid of a parent process given the pid of a child process. | ||
174 | * | ||
175 | * Returns the parent pid or NULL if the parent pid cannot be determined. | ||
176 | */ | ||
177 | static pid_t get_parent_pid(pid_t child) { | ||
178 | pid_t parent = -1; | ||
179 | char file_name[100]; | ||
180 | char *buffer = NULL; | ||
181 | char *token = NULL; | ||
182 | const char *sep = " "; | ||
183 | FILE *stat = NULL; | ||
184 | size_t buf_size = 0; | ||
185 | |||
186 | sprintf(file_name, "/proc/%d/stat", child); | ||
187 | |||
188 | if ((stat = fopen(file_name, "r"))) { | ||
189 | if (getline(&buffer, &buf_size, stat) != -1) { | ||
190 | token = strtok(buffer, sep); // pid | ||
191 | token = strtok(NULL, sep); // executable name | ||
192 | token = strtok(NULL, sep); // state | ||
193 | token = strtok(NULL, sep); // parent pid | ||
194 | parent = strtol(token, NULL, 10); | ||
195 | } | ||
196 | free(buffer); | ||
197 | fclose(stat); | ||
198 | } | ||
199 | |||
200 | if (parent) { | ||
201 | return (parent == child) ? -1 : parent; | ||
202 | } | ||
203 | |||
204 | return -1; | ||
205 | } | ||
206 | |||
172 | struct sway_workspace *root_workspace_for_pid(pid_t pid) { | 207 | struct sway_workspace *root_workspace_for_pid(pid_t pid) { |
173 | if (!pid_workspaces.prev && !pid_workspaces.next) { | 208 | if (!pid_workspaces.prev && !pid_workspaces.next) { |
174 | wl_list_init(&pid_workspaces); | 209 | wl_list_init(&pid_workspaces); |