Skip to content

Commit

Permalink
Merge pull request #2418 from RyanDwyer/separate-root
Browse files Browse the repository at this point in the history
Separate root-related code
  • Loading branch information
emersion authored Aug 4, 2018
2 parents 5de2223 + 30e7e0f commit 0016f77
Show file tree
Hide file tree
Showing 16 changed files with 413 additions and 394 deletions.
26 changes: 0 additions & 26 deletions include/sway/scratchpad.h

This file was deleted.

23 changes: 1 addition & 22 deletions include/sway/tree/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/render/wlr_texture.h>
#include "sway/tree/container.h"
#include "sway/tree/root.h"
#include "config.h"

enum movement_direction {
Expand All @@ -24,28 +25,6 @@ enum resize_edge {

struct sway_container;

struct sway_root {
struct wlr_output_layout *output_layout;

struct wl_listener output_layout_change;
#ifdef HAVE_XWAYLAND
struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
#endif
struct wl_list drag_icons; // sway_drag_icon::link

struct wlr_texture *debug_tree;

struct wl_list outputs; // sway_output::link

list_t *scratchpad; // struct sway_container

struct {
struct wl_signal new_container;
} events;
};

void layout_init(void);

void container_add_child(struct sway_container *parent,
struct sway_container *child);

Expand Down
61 changes: 61 additions & 0 deletions include/sway/tree/root.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef _SWAY_ROOT_H
#define _SWAY_ROOT_H
#include <wayland-server-core.h>
#include <wayland-util.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/render/wlr_texture.h>
#include "sway/tree/container.h"
#include "config.h"
#include "list.h"

extern struct sway_container root_container;

struct sway_root {
struct wlr_output_layout *output_layout;

struct wl_listener output_layout_change;
#ifdef HAVE_XWAYLAND
struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
#endif
struct wl_list drag_icons; // sway_drag_icon::link

struct wlr_texture *debug_tree;

struct wl_list outputs; // sway_output::link

list_t *scratchpad; // struct sway_container

struct {
struct wl_signal new_container;
} events;
};

void root_create(void);

void root_destroy(void);

/**
* Move a container to the scratchpad.
*/
void root_scratchpad_add_container(struct sway_container *con);

/**
* Remove a container from the scratchpad.
*/
void root_scratchpad_remove_container(struct sway_container *con);

/**
* Show a single scratchpad container.
*/
void root_scratchpad_show(struct sway_container *con);

/**
* Hide a single scratchpad container.
*/
void root_scratchpad_hide(struct sway_container *con);

struct sway_container *root_workspace_for_pid(pid_t pid);

void root_record_workspace_pid(pid_t pid);

#endif
4 changes: 0 additions & 4 deletions include/sway/tree/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ void workspace_output_add_priority(struct sway_container *workspace,
struct sway_container *workspace_output_get_highest_available(
struct sway_container *ws, struct sway_container *exclude);

struct sway_container *workspace_for_pid(pid_t pid);

void workspace_record_pid(pid_t pid);

void workspace_detect_urgent(struct sway_container *workspace);

#endif
2 changes: 1 addition & 1 deletion sway/commands/exec_always.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) {
waitpid(pid, NULL, 0);
if (child > 0) {
wlr_log(WLR_DEBUG, "Child process created with pid %d", child);
workspace_record_pid(child);
root_record_workspace_pid(child);
} else {
return cmd_results_new(CMD_FAILURE, "exec_always",
"Second fork() failed");
Expand Down
5 changes: 2 additions & 3 deletions sway/commands/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#include "sway/input/cursor.h"
#include "sway/input/seat.h"
#include "sway/output.h"
#include "sway/scratchpad.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
#include "sway/tree/root.h"
#include "sway/tree/workspace.h"
#include "stringop.h"
#include "list.h"
Expand Down Expand Up @@ -324,7 +323,7 @@ static struct cmd_results *move_to_scratchpad(struct sway_container *con) {
return cmd_results_new(CMD_INVALID, "move",
"Container is already in the scratchpad");
}
scratchpad_add_container(con);
root_scratchpad_add_container(con);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

Expand Down
81 changes: 80 additions & 1 deletion sway/commands/scratchpad.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,87 @@
#include "log.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/scratchpad.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/tree/container.h"
#include "sway/tree/root.h"
#include "sway/tree/workspace.h"

static void scratchpad_toggle_auto(void) {
struct sway_seat *seat = input_manager_current_seat(input_manager);
struct sway_container *focus = seat_get_focus(seat);
struct sway_container *ws = focus->type == C_WORKSPACE ?
focus : container_parent(focus, C_WORKSPACE);

// If the focus is in a floating split container,
// operate on the split container instead of the child.
if (container_is_floating_or_child(focus)) {
while (focus->parent->layout != L_FLOATING) {
focus = focus->parent;
}
}


// Check if the currently focused window is a scratchpad window and should
// be hidden again.
if (focus->scratchpad) {
wlr_log(WLR_DEBUG, "Focus is a scratchpad window - hiding %s",
focus->name);
root_scratchpad_hide(focus);
return;
}

// Check if there is an unfocused scratchpad window on the current workspace
// and focus it.
for (int i = 0; i < ws->sway_workspace->floating->children->length; ++i) {
struct sway_container *floater =
ws->sway_workspace->floating->children->items[i];
if (floater->scratchpad && focus != floater) {
wlr_log(WLR_DEBUG,
"Focusing other scratchpad window (%s) in this workspace",
floater->name);
root_scratchpad_show(floater);
return;
}
}

// Check if there is a visible scratchpad window on another workspace.
// In this case we move it to the current workspace.
for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
struct sway_container *con =
root_container.sway_root->scratchpad->items[i];
if (con->parent) {
wlr_log(WLR_DEBUG,
"Moving a visible scratchpad window (%s) to this workspace",
con->name);
root_scratchpad_show(con);
return;
}
}

// Take the container at the bottom of the scratchpad list
if (!sway_assert(root_container.sway_root->scratchpad->length,
"Scratchpad is empty")) {
return;
}
struct sway_container *con = root_container.sway_root->scratchpad->items[0];
wlr_log(WLR_DEBUG, "Showing %s from list", con->name);
root_scratchpad_show(con);
}

static void scratchpad_toggle_container(struct sway_container *con) {
if (!sway_assert(con->scratchpad, "Container isn't in the scratchpad")) {
return;
}

// Check if it matches a currently visible scratchpad window and hide it.
if (con->parent) {
root_scratchpad_hide(con);
return;
}

root_scratchpad_show(con);
}

struct cmd_results *cmd_scratchpad(int argc, char **argv) {
struct cmd_results *error = NULL;
Expand Down
3 changes: 2 additions & 1 deletion sway/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ int main(int argc, char **argv) {

wlr_log(WLR_INFO, "Starting sway version " SWAY_VERSION);

layout_init();
root_create();

if (!server_init(&server)) {
return 1;
Expand Down Expand Up @@ -464,6 +464,7 @@ int main(int argc, char **argv) {
wlr_log(WLR_INFO, "Shutting down sway");

server_fini(&server);
root_destroy();

if (config) {
free_config(config);
Expand Down
2 changes: 1 addition & 1 deletion sway/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ sway_sources = files(
'debug-tree.c',
'ipc-json.c',
'ipc-server.c',
'scratchpad.c',
'security.c',
'swaynag.c',

Expand Down Expand Up @@ -150,6 +149,7 @@ sway_sources = files(
'tree/arrange.c',
'tree/container.c',
'tree/layout.c',
'tree/root.c',
'tree/view.c',
'tree/workspace.c',
'tree/output.c',
Expand Down
Loading

0 comments on commit 0016f77

Please sign in to comment.