mirror of
https://github.com/swaywm/sway.git
synced 2026-04-28 06:46:26 -04:00
added scratchpad (WIP)
views that are pushed to the scratchpad still render and accept input. latter only if no other view took focus afterwards
This commit is contained in:
parent
4e0a3b9c72
commit
f4b4c5851a
3 changed files with 50 additions and 3 deletions
|
|
@ -32,4 +32,9 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed
|
|||
|
||||
void view_set_floating(swayc_t *view, bool floating);
|
||||
|
||||
// Scratchpad
|
||||
|
||||
void scratchpad_push(swayc_t *view);
|
||||
swayc_t *scratchpad_pop(void);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -200,13 +200,13 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
|
|||
swayc_t *view = get_focused_container(&root_container);
|
||||
|
||||
bool floating;
|
||||
if (strcasecmp(argv[0], "toggle") != 0) {
|
||||
if (strcasecmp(argv[0], "toggle") == 0) {
|
||||
floating = !view->is_floating;
|
||||
}
|
||||
else if (strcasecmp(argv[0], "enable") != 0) {
|
||||
else if (strcasecmp(argv[0], "enable") == 0) {
|
||||
floating = true;
|
||||
}
|
||||
else if (strcasecmp(argv[0], "disable") != 0) {
|
||||
else if (strcasecmp(argv[0], "disable") == 0) {
|
||||
floating = false;
|
||||
}
|
||||
else {
|
||||
|
|
@ -326,12 +326,36 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) {
|
|||
move_container(view,&root_container,MOVE_UP);
|
||||
} else if (strcasecmp(argv[0], "down") == 0) {
|
||||
move_container(view,&root_container,MOVE_DOWN);
|
||||
} else if (strcasecmp(argv[0], "scratchpad") == 0) {
|
||||
swayc_t *parent = view->parent;
|
||||
destroy_container(remove_child(view));
|
||||
scratchpad_push(view);
|
||||
set_focused_container(parent);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cmd_scratchpad(struct sway_config *config, int argc, char **argv) {
|
||||
if (!checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[0], "show") != 0) {
|
||||
sway_log(L_ERROR, "scratchpad - unknown token '%s', expected show", argv[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
swayc_t *view = scratchpad_pop();
|
||||
if (view == NULL) {
|
||||
return false;
|
||||
}
|
||||
view_set_floating(view, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cmd_output(struct sway_config *config, int argc, char **argv) {
|
||||
if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) {
|
||||
return false;
|
||||
|
|
@ -668,6 +692,7 @@ static struct cmd_handler handlers[] = {
|
|||
{ "output", cmd_output},
|
||||
{ "reload", cmd_reload },
|
||||
{ "resize", cmd_resize },
|
||||
{ "scratchpad", cmd_scratchpad },
|
||||
{ "set", cmd_set },
|
||||
{ "split", cmd_split },
|
||||
{ "splith", cmd_splith },
|
||||
|
|
|
|||
|
|
@ -14,11 +14,15 @@ swayc_t root_container;
|
|||
int min_sane_h = 60;
|
||||
int min_sane_w = 100;
|
||||
|
||||
static swayc_t *scratchpad = NULL;
|
||||
|
||||
void init_layout(void) {
|
||||
root_container.type = C_ROOT;
|
||||
root_container.layout = L_NONE;
|
||||
root_container.children = create_list();
|
||||
root_container.handle = -1;
|
||||
|
||||
scratchpad = new_workspace(&root_container, "__i3_scratch");
|
||||
}
|
||||
|
||||
static int index_child(swayc_t *parent, swayc_t *child) {
|
||||
|
|
@ -464,3 +468,16 @@ void view_set_floating(swayc_t *view, bool floating) {
|
|||
arrange_windows(swayc_active_workspace(), -1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void scratchpad_push(swayc_t *view) {
|
||||
add_floating(scratchpad, view);
|
||||
}
|
||||
|
||||
swayc_t *scratchpad_pop(void) {
|
||||
if (scratchpad->floating->length == 0) {
|
||||
return NULL;
|
||||
}
|
||||
swayc_t *view = scratchpad->floating->items[0];
|
||||
remove_child(view);
|
||||
return view;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue