mirror of
https://github.com/swaywm/sway.git
synced 2025-11-18 06:59:48 -05:00
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 .
This commit is contained in:
parent
410c961388
commit
d7ff776552
12 changed files with 135 additions and 143 deletions
|
|
@ -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++) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue