aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/scratchpad.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-03 23:06:01 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-04 14:01:20 +1000
commit04489ff4209dc073027419d90961367cfb998fe8 (patch)
treed6f6213d2374e10a875e8ced872511e6e656ae3e /sway/commands/scratchpad.c
parentMerge pull request #2419 from RedSoxFan/fix-2416 (diff)
downloadsway-04489ff4209dc073027419d90961367cfb998fe8.tar.gz
sway-04489ff4209dc073027419d90961367cfb998fe8.tar.zst
sway-04489ff4209dc073027419d90961367cfb998fe8.zip
Separate root-related code
This creates a root.c and moves bits and pieces from elsewhere into it. * layout_init has been renamed to root_create and moved into root.c * root_destroy has been created and is called on shutdown * scratchpad code has been moved into root.c, because hidden scratchpad containers are stored in the root struct
Diffstat (limited to 'sway/commands/scratchpad.c')
-rw-r--r--sway/commands/scratchpad.c81
1 files changed, 80 insertions, 1 deletions
diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c
index 01a91d65..0e573aeb 100644
--- a/sway/commands/scratchpad.c
+++ b/sway/commands/scratchpad.c
@@ -1,8 +1,87 @@
1#include "log.h" 1#include "log.h"
2#include "sway/commands.h" 2#include "sway/commands.h"
3#include "sway/config.h" 3#include "sway/config.h"
4#include "sway/scratchpad.h" 4#include "sway/input/input-manager.h"
5#include "sway/input/seat.h"
5#include "sway/tree/container.h" 6#include "sway/tree/container.h"
7#include "sway/tree/root.h"
8#include "sway/tree/workspace.h"
9
10static void scratchpad_toggle_auto(void) {
11 struct sway_seat *seat = input_manager_current_seat(input_manager);
12 struct sway_container *focus = seat_get_focus(seat);
13 struct sway_container *ws = focus->type == C_WORKSPACE ?
14 focus : container_parent(focus, C_WORKSPACE);
15
16 // If the focus is in a floating split container,
17 // operate on the split container instead of the child.
18 if (container_is_floating_or_child(focus)) {
19 while (focus->parent->layout != L_FLOATING) {
20 focus = focus->parent;
21 }
22 }
23
24
25 // Check if the currently focused window is a scratchpad window and should
26 // be hidden again.
27 if (focus->scratchpad) {
28 wlr_log(WLR_DEBUG, "Focus is a scratchpad window - hiding %s",
29 focus->name);
30 root_scratchpad_hide(focus);
31 return;
32 }
33
34 // Check if there is an unfocused scratchpad window on the current workspace
35 // and focus it.
36 for (int i = 0; i < ws->sway_workspace->floating->children->length; ++i) {
37 struct sway_container *floater =
38 ws->sway_workspace->floating->children->items[i];
39 if (floater->scratchpad && focus != floater) {
40 wlr_log(WLR_DEBUG,
41 "Focusing other scratchpad window (%s) in this workspace",
42 floater->name);
43 root_scratchpad_show(floater);
44 return;
45 }
46 }
47
48 // Check if there is a visible scratchpad window on another workspace.
49 // In this case we move it to the current workspace.
50 for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
51 struct sway_container *con =
52 root_container.sway_root->scratchpad->items[i];
53 if (con->parent) {
54 wlr_log(WLR_DEBUG,
55 "Moving a visible scratchpad window (%s) to this workspace",
56 con->name);
57 root_scratchpad_show(con);
58 return;
59 }
60 }
61
62 // Take the container at the bottom of the scratchpad list
63 if (!sway_assert(root_container.sway_root->scratchpad->length,
64 "Scratchpad is empty")) {
65 return;
66 }
67 struct sway_container *con = root_container.sway_root->scratchpad->items[0];
68 wlr_log(WLR_DEBUG, "Showing %s from list", con->name);
69 root_scratchpad_show(con);
70}
71
72static void scratchpad_toggle_container(struct sway_container *con) {
73 if (!sway_assert(con->scratchpad, "Container isn't in the scratchpad")) {
74 return;
75 }
76
77 // Check if it matches a currently visible scratchpad window and hide it.
78 if (con->parent) {
79 root_scratchpad_hide(con);
80 return;
81 }
82
83 root_scratchpad_show(con);
84}
6 85
7struct cmd_results *cmd_scratchpad(int argc, char **argv) { 86struct cmd_results *cmd_scratchpad(int argc, char **argv) {
8 struct cmd_results *error = NULL; 87 struct cmd_results *error = NULL;