diff --git a/src/ext-protocol/ext-workspace.h b/src/ext-protocol/ext-workspace.h index 516a411..6e1a747 100644 --- a/src/ext-protocol/ext-workspace.h +++ b/src/ext-protocol/ext-workspace.h @@ -1,5 +1,9 @@ #include "wlr_ext_workspace_v1.h" +#define EXT_WORKSPACE_ENABLE_CAPS \ + WLR_EXT_WORKSPACE_HANDLE_V1_CAP_ACTIVATE | \ + WLR_EXT_WORKSPACE_HANDLE_V1_CAP_DEACTIVATE + typedef struct Monitor Monitor; struct workspace { @@ -28,6 +32,17 @@ void goto_workspace(struct workspace *target) { } } +void toggle_workspace(struct workspace *target) { + unsigned int tag; + tag = 1 << (target->tag - 1); + if (target->tag == 0) { + toggleview(&(Arg){.i = -1}); + return; + } else { + toggleview(&(Arg){.ui = tag}); + } +} + static void handle_ext_workspace_activate(struct wl_listener *listener, void *data) { struct workspace *workspace = @@ -36,6 +51,14 @@ static void handle_ext_workspace_activate(struct wl_listener *listener, wlr_log(WLR_INFO, "ext activating workspace %d", workspace->tag); } +static void handle_ext_workspace_deactivate(struct wl_listener *listener, + void *data) { + struct workspace *workspace = + wl_container_of(listener, workspace, deactivate); + toggle_workspace(workspace); + wlr_log(WLR_INFO, "ext deactivating workspace %d", workspace->tag); +} + static const char *get_name_from_tag(unsigned int tag) { static const char *names[] = {"overview", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; @@ -44,6 +67,7 @@ static const char *get_name_from_tag(unsigned int tag) { void destroy_workspace(struct workspace *workspace) { wl_list_remove(&workspace->activate.link); + wl_list_remove(&workspace->deactivate.link); wlr_ext_workspace_handle_v1_destroy(workspace->ext_workspace); wl_list_remove(&workspace->link); free(workspace); @@ -77,13 +101,18 @@ static void add_workspace_by_tag(int tag, Monitor *m) { workspace->tag = tag; workspace->m = m; workspace->ext_workspace = wlr_ext_workspace_handle_v1_create( - ext_manager, name, WLR_EXT_WORKSPACE_HANDLE_V1_CAP_ACTIVATE); + ext_manager, name, EXT_WORKSPACE_ENABLE_CAPS); wlr_ext_workspace_handle_v1_set_group(workspace->ext_workspace, m->ext_group); wlr_ext_workspace_handle_v1_set_name(workspace->ext_workspace, name); + workspace->activate.notify = handle_ext_workspace_activate; wl_signal_add(&workspace->ext_workspace->events.activate, &workspace->activate); + + workspace->deactivate.notify = handle_ext_workspace_deactivate; + wl_signal_add(&workspace->ext_workspace->events.deactivate, + &workspace->deactivate); } void dwl_ext_workspace_printstatus(Monitor *m) { diff --git a/src/mango.c b/src/mango.c index 9d1b76f..2c9ddcf 100644 --- a/src/mango.c +++ b/src/mango.c @@ -2605,7 +2605,7 @@ void createmon(struct wl_listener *listener, void *data) { wlr_output_layout_add(output_layout, wlr_output, m->m.x, m->m.y); m->ext_group = wlr_ext_workspace_group_handle_v1_create( - ext_manager, WLR_EXT_WORKSPACE_HANDLE_V1_CAP_ACTIVATE); + ext_manager, EXT_WORKSPACE_ENABLE_CAPS); wlr_ext_workspace_group_handle_v1_output_enter(m->ext_group, m->wlr_output); for (i = 1; i <= LENGTH(tags); i++) {