diff options
author | 2019-01-22 01:02:48 -0500 | |
---|---|---|
committer | 2019-01-22 01:02:48 -0500 | |
commit | f493fb526d3aabb4e756409a3a69e304759f4201 (patch) | |
tree | 239b2c3d5212a5663eb3c0868543f505b03d3953 /sway/tree/root.c | |
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/root.c')
-rw-r--r-- | sway/tree/root.c | 35 |
1 files changed, 35 insertions, 0 deletions
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); |