diff options
author | M Stoeckl <code@mstoeckl.com> | 2019-01-21 12:39:16 -0500 |
---|---|---|
committer | M Stoeckl <code@mstoeckl.com> | 2019-01-21 12:39:16 -0500 |
commit | d7ff776552bef524e905d85c2a5e7651c8408658 (patch) | |
tree | ae20feac64f93f776e9c9e136c62459705e97987 /sway/tree/root.c | |
parent | swaybar: fix setting floating watcher slots (diff) | |
download | sway-d7ff776552bef524e905d85c2a5e7651c8408658.tar.gz sway-d7ff776552bef524e905d85c2a5e7651c8408658.tar.zst sway-d7ff776552bef524e905d85c2a5e7651c8408658.zip |
Move sway-specific functions in common/util.c into sway/
Modifier handling functions were moved into sway/input/keyboard.c;
opposite_direction for enum wlr_direction into sway/tree/output.c;
and get_parent_pid into sway/tree/root.c .
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); |