aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-01-22 01:02:48 -0500
committerGitHub <noreply@github.com>2019-01-22 01:02:48 -0500
commitf493fb526d3aabb4e756409a3a69e304759f4201 (patch)
tree239b2c3d5212a5663eb3c0868543f505b03d3953 /sway/tree
parent410c961388bbfecb5f1b63e4a1977a78709a6e57 (diff)
parent4b1eaaf731b0e29497edc4c85153f2cf417fb5ce (diff)
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.c16
-rw-r--r--sway/tree/root.c35
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 @@
#define _POSIX_C_SOURCE 200809L
+#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
@@ -12,6 +13,21 @@
#include "log.h"
#include "util.h"
+enum wlr_direction opposite_direction(enum wlr_direction d) {
+ switch (d) {
+ case WLR_DIRECTION_UP:
+ return WLR_DIRECTION_DOWN;
+ case WLR_DIRECTION_DOWN:
+ return WLR_DIRECTION_UP;
+ case WLR_DIRECTION_RIGHT:
+ return WLR_DIRECTION_LEFT;
+ case WLR_DIRECTION_LEFT:
+ return WLR_DIRECTION_RIGHT;
+ }
+ assert(false);
+ return 0;
+}
+
static void restore_workspaces(struct sway_output *output) {
// Workspace output priority
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 {
static struct wl_list pid_workspaces;
+/**
+ * Get the pid of a parent process given the pid of a child process.
+ *
+ * Returns the parent pid or NULL if the parent pid cannot be determined.
+ */
+static pid_t get_parent_pid(pid_t child) {
+ pid_t parent = -1;
+ char file_name[100];
+ char *buffer = NULL;
+ char *token = NULL;
+ const char *sep = " ";
+ FILE *stat = NULL;
+ size_t buf_size = 0;
+
+ sprintf(file_name, "/proc/%d/stat", child);
+
+ if ((stat = fopen(file_name, "r"))) {
+ if (getline(&buffer, &buf_size, stat) != -1) {
+ token = strtok(buffer, sep); // pid
+ token = strtok(NULL, sep); // executable name
+ token = strtok(NULL, sep); // state
+ token = strtok(NULL, sep); // parent pid
+ parent = strtol(token, NULL, 10);
+ }
+ free(buffer);
+ fclose(stat);
+ }
+
+ if (parent) {
+ return (parent == child) ? -1 : parent;
+ }
+
+ return -1;
+}
+
struct sway_workspace *root_workspace_for_pid(pid_t pid) {
if (!pid_workspaces.prev && !pid_workspaces.next) {
wl_list_init(&pid_workspaces);