mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 07:51:28 +00:00
semi-working (only non-client/server wayland apps)
This commit is contained in:
parent
0f1859ed25
commit
03d79b41c7
|
@ -1,6 +1,10 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "readline.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
int wrap(int i, int max) {
|
int wrap(int i, int max) {
|
||||||
return ((i % max) + max) % max;
|
return ((i % max) + max) % max;
|
||||||
|
@ -64,3 +68,36 @@ int get_modifier_names(const char **names, uint32_t modifier_masks) {
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t get_parent_pid(pid_t child) {
|
||||||
|
pid_t parent;
|
||||||
|
char file_name[100];
|
||||||
|
char *buffer = NULL;
|
||||||
|
char *token = NULL;
|
||||||
|
const char sep[2] = " ";
|
||||||
|
FILE *stat = NULL;
|
||||||
|
|
||||||
|
sway_log(L_DEBUG, "trying to get parent pid for child pid %d", child);
|
||||||
|
|
||||||
|
sprintf(file_name, "/proc/%d/stat", child);
|
||||||
|
|
||||||
|
if (!(stat = fopen(file_name, "r")) || !(buffer = read_line(stat))) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(stat);
|
||||||
|
|
||||||
|
sway_log(L_DEBUG, "buffer string is %s", buffer);
|
||||||
|
|
||||||
|
token = strtok(buffer, sep);
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
token = strtok(NULL, sep);
|
||||||
|
}
|
||||||
|
|
||||||
|
parent = strtol(token, NULL, 10);
|
||||||
|
|
||||||
|
sway_log(L_DEBUG, "found parent pid %d for child pid %d", parent, child);
|
||||||
|
|
||||||
|
return (parent == child) ? -1 : parent;
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define _SWAY_UTIL_H
|
#define _SWAY_UTIL_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <wlc/wlc.h>
|
#include <wlc/wlc.h>
|
||||||
#include <xkbcommon/xkbcommon.h>
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
|
||||||
|
@ -36,4 +37,11 @@ const char *get_modifier_name_by_mask(uint32_t modifier);
|
||||||
*/
|
*/
|
||||||
int get_modifier_names(const char **names, uint32_t modifier_masks);
|
int get_modifier_names(const char **names, uint32_t modifier_masks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
pid_t get_parent_pid(pid_t pid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
#include <wlc/wlc-render.h>
|
#include <wlc/wlc-render.h>
|
||||||
#include <wlc/wlc-wayland.h>
|
#include <wlc/wlc-wayland.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include "handlers.h"
|
#include "handlers.h"
|
||||||
#include "border.h"
|
#include "border.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -180,6 +182,12 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
wlc_handle parent = wlc_view_get_parent(handle);
|
wlc_handle parent = wlc_view_get_parent(handle);
|
||||||
swayc_t *focused = NULL;
|
swayc_t *focused = NULL;
|
||||||
swayc_t *newview = NULL;
|
swayc_t *newview = NULL;
|
||||||
|
swayc_t *current_ws = swayc_active_workspace();
|
||||||
|
bool return_to_workspace = false;
|
||||||
|
|
||||||
|
if (current_ws) {
|
||||||
|
sway_log(L_DEBUG, "current workspace is %s", current_ws->name);
|
||||||
|
}
|
||||||
|
|
||||||
// Get parent container, to add view in
|
// Get parent container, to add view in
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
@ -209,16 +217,22 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
if (pid) {
|
if (pid) {
|
||||||
sway_log(L_DEBUG, "found pid %d for client", pid);
|
sway_log(L_DEBUG, "found pid %d for client", pid);
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < config->pid_workspaces->length; i++) {
|
do {
|
||||||
pw = config->pid_workspaces->items[i];
|
for (i = 0; i < config->pid_workspaces->length; i++) {
|
||||||
pid_t *pw_pid = pw->pid;
|
pw = config->pid_workspaces->items[i];
|
||||||
sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i);
|
pid_t *pw_pid = pw->pid;
|
||||||
if (pid == *pw_pid) {
|
sway_log(L_DEBUG, "checking pid %d against pid %d, i is %d", pid, *pw_pid, i);
|
||||||
sway_log(L_DEBUG, "found pid_workspace for pid, %d %s", pid, pw->workspace);
|
if (pid == *pw_pid) {
|
||||||
break;
|
sway_log(L_DEBUG, "found pid_workspace for pid, %d %s", pid, pw->workspace);
|
||||||
|
break; // out of for loop
|
||||||
|
}
|
||||||
|
pw = NULL;
|
||||||
}
|
}
|
||||||
pw = NULL;
|
if (pw) {
|
||||||
}
|
break; // out of do-while loop
|
||||||
|
}
|
||||||
|
pid = get_parent_pid(pid);
|
||||||
|
} while (pid > -1 && pid != getpid());
|
||||||
|
|
||||||
swayc_t *ws = NULL;
|
swayc_t *ws = NULL;
|
||||||
|
|
||||||
|
@ -233,6 +247,10 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
if (ws) {
|
if (ws) {
|
||||||
sway_log(L_DEBUG, "workspace exists, name is %s", ws->name);
|
sway_log(L_DEBUG, "workspace exists, name is %s", ws->name);
|
||||||
focused = ws;
|
focused = ws;
|
||||||
|
|
||||||
|
if (current_ws && (strcmp(current_ws->name, ws->name) != 0)) {
|
||||||
|
return_to_workspace = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list_del(config->pid_workspaces, i);
|
list_del(config->pid_workspaces, i);
|
||||||
|
@ -240,7 +258,6 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
free_pid_workspace(pw);
|
free_pid_workspace(pw);
|
||||||
// free(&pid);
|
|
||||||
|
|
||||||
if (!focused || focused->type == C_OUTPUT) {
|
if (!focused || focused->type == C_OUTPUT) {
|
||||||
focused = get_focused_container(&root_container);
|
focused = get_focused_container(&root_container);
|
||||||
|
@ -330,6 +347,12 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
list_add(output->unmanaged, h);
|
list_add(output->unmanaged, h);
|
||||||
}
|
}
|
||||||
wlc_view_set_mask(handle, VISIBLE);
|
wlc_view_set_mask(handle, VISIBLE);
|
||||||
|
|
||||||
|
if (return_to_workspace && current_ws) {
|
||||||
|
sway_log(L_DEBUG, "return_to_workspace && current_ws");
|
||||||
|
workspace_switch(current_ws);
|
||||||
|
set_focused_container(current_ws->focused);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue