2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2020-09-25 19:42:40 +01:00
|
|
|
#include <strings.h>
|
2021-07-23 21:15:55 +01:00
|
|
|
#include <wlr/util/log.h>
|
2020-09-28 20:41:41 +01:00
|
|
|
#include "common/spawn.h"
|
2020-09-25 20:05:20 +01:00
|
|
|
#include "labwc.h"
|
2020-10-31 15:27:22 +00:00
|
|
|
#include "menu/menu.h"
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_menu(struct server *server, const char *menu)
|
|
|
|
|
{
|
|
|
|
|
if (!menu) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!strcasecmp(menu, "root-menu")) {
|
|
|
|
|
server->input_mode = LAB_INPUT_STATE_MENU;
|
|
|
|
|
menu_move(server->rootmenu, server->seat.cursor->x,
|
|
|
|
|
server->seat.cursor->y);
|
|
|
|
|
}
|
2021-01-09 22:51:20 +00:00
|
|
|
damage_all_outputs(server);
|
2020-10-31 15:27:22 +00:00
|
|
|
}
|
2020-06-18 20:18:01 +01:00
|
|
|
|
2021-12-03 16:37:53 +00:00
|
|
|
static struct view *
|
|
|
|
|
activator_or_focused_view(struct view *activator, struct server *server)
|
|
|
|
|
{
|
|
|
|
|
return activator ? activator : desktop_focused_view(server);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
2021-12-03 16:37:53 +00:00
|
|
|
action(struct view *activator, struct server *server, const char *action, const char *command, uint32_t resize_edges)
|
2020-06-18 20:18:01 +01:00
|
|
|
{
|
2020-09-25 19:37:51 +01:00
|
|
|
if (!action)
|
2020-06-18 20:18:01 +01:00
|
|
|
return;
|
2021-07-12 21:46:10 +01:00
|
|
|
if (!strcasecmp(action, "Close")) {
|
2021-12-03 16:37:53 +00:00
|
|
|
struct view *view = activator_or_focused_view(activator, server);
|
2021-07-13 21:54:22 +01:00
|
|
|
if (view) {
|
|
|
|
|
view->impl->close(view);
|
|
|
|
|
}
|
2021-07-12 21:46:10 +01:00
|
|
|
} else if (!strcasecmp(action, "Debug")) {
|
2020-10-31 15:27:22 +00:00
|
|
|
/* nothing */
|
2020-09-25 19:42:40 +01:00
|
|
|
} else if (!strcasecmp(action, "Execute")) {
|
2021-06-30 19:56:31 +01:00
|
|
|
struct buf cmd;
|
|
|
|
|
buf_init(&cmd);
|
|
|
|
|
buf_add(&cmd, command);
|
|
|
|
|
buf_expand_shell_variables(&cmd);
|
|
|
|
|
spawn_async_no_shell(cmd.buf);
|
|
|
|
|
free(cmd.buf);
|
2020-10-31 15:27:22 +00:00
|
|
|
} else if (!strcasecmp(action, "Exit")) {
|
|
|
|
|
wl_display_terminate(server->wl_display);
|
2021-07-20 19:54:57 +01:00
|
|
|
} else if (!strcasecmp(action, "MoveToEdge")) {
|
2021-12-03 16:37:53 +00:00
|
|
|
view_move_to_edge(activator_or_focused_view(activator, server), command);
|
2021-10-17 00:44:24 +00:00
|
|
|
} else if (!strcasecmp(action, "SnapToEdge")) {
|
2021-12-03 16:37:53 +00:00
|
|
|
view_snap_to_edge(activator_or_focused_view(activator, server), command);
|
2020-09-25 19:37:51 +01:00
|
|
|
} else if (!strcasecmp(action, "NextWindow")) {
|
2020-09-11 20:48:28 +01:00
|
|
|
server->cycle_view =
|
2021-12-04 10:06:21 -05:00
|
|
|
desktop_cycle_view(server, server->cycle_view, LAB_CYCLE_DIR_FORWARD);
|
2021-08-16 07:16:56 +01:00
|
|
|
osd_update(server);
|
2021-12-03 01:07:24 +00:00
|
|
|
} else if (!strcasecmp(action, "PreviousWindow")) {
|
|
|
|
|
server->cycle_view =
|
|
|
|
|
desktop_cycle_view(server, server->cycle_view, LAB_CYCLE_DIR_BACKWARD);
|
|
|
|
|
osd_update(server);
|
2020-09-25 19:42:40 +01:00
|
|
|
} else if (!strcasecmp(action, "Reconfigure")) {
|
2020-10-21 20:30:59 +01:00
|
|
|
spawn_async_no_shell("killall -SIGHUP labwc");
|
2020-10-31 15:27:22 +00:00
|
|
|
} else if (!strcasecmp(action, "ShowMenu")) {
|
|
|
|
|
show_menu(server, command);
|
2021-07-13 21:54:22 +01:00
|
|
|
} else if (!strcasecmp(action, "ToggleMaximize")) {
|
2021-12-03 16:37:53 +00:00
|
|
|
struct view *view = activator_or_focused_view(activator, server);
|
2021-08-02 16:49:41 +01:00
|
|
|
if (view) {
|
|
|
|
|
view_toggle_maximize(view);
|
2021-07-13 21:54:22 +01:00
|
|
|
}
|
2021-09-19 22:16:56 +00:00
|
|
|
} else if (!strcasecmp(action, "ToggleFullscreen")) {
|
2021-12-03 16:37:53 +00:00
|
|
|
struct view *view = activator_or_focused_view(activator, server);
|
2021-09-19 22:16:56 +00:00
|
|
|
if (view) {
|
|
|
|
|
view_toggle_fullscreen(view);
|
|
|
|
|
}
|
|
|
|
|
} else if (!strcasecmp(action, "ToggleDecorations")) {
|
2021-12-03 16:37:53 +00:00
|
|
|
struct view *view = activator_or_focused_view(activator, server);
|
2021-09-19 22:16:56 +00:00
|
|
|
if (view) {
|
|
|
|
|
view_toggle_decorations(view);
|
|
|
|
|
}
|
2021-12-01 22:07:07 +00:00
|
|
|
} else if (!strcasecmp(action, "Focus")) {
|
|
|
|
|
struct view *view = desktop_view_at_cursor(server);
|
|
|
|
|
if (view) {
|
|
|
|
|
desktop_focus_and_activate_view(&server->seat, view);
|
|
|
|
|
damage_all_outputs(server);
|
|
|
|
|
}
|
2021-09-19 22:17:45 +00:00
|
|
|
} else if (!strcasecmp(action, "Iconify")) {
|
2021-12-03 16:37:53 +00:00
|
|
|
struct view *view = activator_or_focused_view(activator, server);
|
2021-09-19 22:17:45 +00:00
|
|
|
if (view) {
|
|
|
|
|
view_minimize(view, true);
|
|
|
|
|
}
|
2021-11-26 13:03:15 -05:00
|
|
|
} else if (!strcasecmp(action, "Move")) {
|
|
|
|
|
struct view *view = desktop_view_at_cursor(server);
|
|
|
|
|
if (view) {
|
|
|
|
|
interactive_begin(view, LAB_INPUT_STATE_MOVE, 0);
|
|
|
|
|
}
|
2021-12-01 22:07:07 +00:00
|
|
|
} else if (!strcasecmp(action, "Raise")) {
|
2021-12-03 16:37:53 +00:00
|
|
|
struct view *view = activator_or_focused_view(activator, server);
|
2021-12-01 22:07:07 +00:00
|
|
|
if (view) {
|
2021-12-06 21:23:49 +00:00
|
|
|
desktop_move_to_front(view);
|
2021-12-01 22:07:07 +00:00
|
|
|
damage_all_outputs(server);
|
|
|
|
|
}
|
2021-12-01 02:38:53 +00:00
|
|
|
} else if (!strcasecmp(action, "Resize")) {
|
|
|
|
|
struct view *view = desktop_view_at_cursor(server);
|
|
|
|
|
if (view) {
|
|
|
|
|
interactive_begin(view, LAB_INPUT_STATE_RESIZE, resize_edges);
|
|
|
|
|
}
|
2020-06-18 20:18:01 +01:00
|
|
|
} else {
|
2021-07-23 21:15:55 +01:00
|
|
|
wlr_log(WLR_ERROR, "action (%s) not supported", action);
|
2020-06-18 20:18:01 +01:00
|
|
|
}
|
|
|
|
|
}
|