mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
Add window menu
This commit is contained in:
parent
4bc8726abd
commit
759b26b5c1
12 changed files with 108 additions and 11 deletions
|
|
@ -50,7 +50,7 @@ Actions are used in keyboard bindings.
|
||||||
Re-load configuration and theme files.
|
Re-load configuration and theme files.
|
||||||
|
|
||||||
*<action name="ShowMenu"><menu>*
|
*<action name="ShowMenu"><menu>*
|
||||||
Show menu. Valid menu name is "root-menu".
|
Show menu. Valid menu names are "root-menu" and "client-menu".
|
||||||
|
|
||||||
*<action name="ToggleDecorations">*
|
*<action name="ToggleDecorations">*
|
||||||
Toggle decorations of focused window.
|
Toggle decorations of focused window.
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,7 @@ Configuration must be wrapped in a <labwc_config> root-node.
|
||||||
Define a mouse binding. Supported context-names include:
|
Define a mouse binding. Supported context-names include:
|
||||||
- TitleBar: The area where the title of the window is shown.
|
- TitleBar: The area where the title of the window is shown.
|
||||||
- Title: The title of the window itself.
|
- Title: The title of the window itself.
|
||||||
|
- WindowMenu: The button on the left.
|
||||||
- Iconify: The button that looks like an underline.
|
- Iconify: The button that looks like an underline.
|
||||||
- Maximize: The button that looks like a box.
|
- Maximize: The button that looks like a box.
|
||||||
- Close: The button that looks like an X.
|
- Close: The button that looks like an X.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,23 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<openbox_menu>
|
<openbox_menu>
|
||||||
|
<menu id="client-menu" label="ClientMenu">
|
||||||
|
<item label="Minimize">
|
||||||
|
<action name="Iconify" />
|
||||||
|
</item>
|
||||||
|
<item label="Maximize">
|
||||||
|
<action name="ToggleMaximize" />
|
||||||
|
</item>
|
||||||
|
<item label="Fullscreen">
|
||||||
|
<action name="ToggleFullscreen" />
|
||||||
|
</item>
|
||||||
|
<item label="Decorations">
|
||||||
|
<action name="ToggleDecorations" />
|
||||||
|
</item>
|
||||||
|
<item label="Close">
|
||||||
|
<action name="Close" />
|
||||||
|
</item>
|
||||||
|
</menu>
|
||||||
<menu id="root-menu" label="">
|
<menu id="root-menu" label="">
|
||||||
<item label="Web browser">
|
<item label="Web browser">
|
||||||
<action name="Execute"><command>firefox</command></action>
|
<action name="Execute"><command>firefox</command></action>
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,9 @@
|
||||||
<keybind key="W-Down">
|
<keybind key="W-Down">
|
||||||
<action name="SnapToEdge"><direction>down</direction></action>
|
<action name="SnapToEdge"><direction>down</direction></action>
|
||||||
</keybind>
|
</keybind>
|
||||||
|
<keybind key="A-Space">
|
||||||
|
<action name="ShowMenu"><menu>client-menu</menu></action>
|
||||||
|
</keybind>
|
||||||
<keybind key="XF86_AudioLowerVolume">
|
<keybind key="XF86_AudioLowerVolume">
|
||||||
<action name="Execute"><command>amixer sset Master 5%-</command></action>
|
<action name="Execute"><command>amixer sset Master 5%-</command></action>
|
||||||
</keybind>
|
</keybind>
|
||||||
|
|
@ -190,6 +193,13 @@
|
||||||
<mousebind button="Left" action="Drag">
|
<mousebind button="Left" action="Drag">
|
||||||
<action name="Move"/>
|
<action name="Move"/>
|
||||||
</mousebind>
|
</mousebind>
|
||||||
|
<mousebind button="Right" action="Click">
|
||||||
|
<action name="Focus" />
|
||||||
|
<action name="Raise" />
|
||||||
|
<action name="ShowMenu">
|
||||||
|
<menu>client-menu</menu>
|
||||||
|
</action>
|
||||||
|
</mousebind>
|
||||||
<mousebind button="Left" action="DoubleClick">
|
<mousebind button="Left" action="DoubleClick">
|
||||||
<action name="Focus"/>
|
<action name="Focus"/>
|
||||||
<action name="Raise"/>
|
<action name="Raise"/>
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,7 @@ struct server {
|
||||||
|
|
||||||
struct theme *theme;
|
struct theme *theme;
|
||||||
struct menu *rootmenu;
|
struct menu *rootmenu;
|
||||||
|
struct menu *windowmenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct output {
|
struct output {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ struct menu {
|
||||||
};
|
};
|
||||||
|
|
||||||
void menu_init_rootmenu(struct server *server);
|
void menu_init_rootmenu(struct server *server);
|
||||||
|
void menu_init_windowmenu(struct server *server);
|
||||||
void menu_finish(void);
|
void menu_finish(void);
|
||||||
|
|
||||||
/* menu_move - move to position (x, y) */
|
/* menu_move - move to position (x, y) */
|
||||||
|
|
|
||||||
35
src/action.c
35
src/action.c
|
|
@ -87,16 +87,37 @@ void action_list_free(struct wl_list *action_list) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
show_menu(struct server *server, const char *menu)
|
show_menu(struct server *server, struct view *view, const char *menu_name)
|
||||||
{
|
{
|
||||||
if (!menu) {
|
struct menu *menu = NULL;
|
||||||
|
bool force_menu_top_left = false;
|
||||||
|
|
||||||
|
if (!menu_name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!strcasecmp(menu, "root-menu")) {
|
|
||||||
server->input_mode = LAB_INPUT_STATE_MENU;
|
if (!strcasecmp(menu_name, "root-menu")) {
|
||||||
menu_move(server->rootmenu, server->seat.cursor->x,
|
menu = server->rootmenu;
|
||||||
server->seat.cursor->y);
|
server->windowmenu->visible = false;
|
||||||
|
} else if (!strcasecmp(menu_name, "client-menu") && view) {
|
||||||
|
menu = server->windowmenu;
|
||||||
|
server->rootmenu->visible = false;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menu->visible = true;
|
||||||
|
server->input_mode = LAB_INPUT_STATE_MENU;
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
if (force_menu_top_left) {
|
||||||
|
x = view->x;
|
||||||
|
y = view->y;
|
||||||
|
} else {
|
||||||
|
x = server->seat.cursor->x;
|
||||||
|
y = server->seat.cursor->y;
|
||||||
|
}
|
||||||
|
menu_move(menu, x, y);
|
||||||
damage_all_outputs(server);
|
damage_all_outputs(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,7 +187,7 @@ action(struct view *activator, struct server *server, struct wl_list *actions, u
|
||||||
spawn_async_no_shell("killall -SIGHUP labwc");
|
spawn_async_no_shell("killall -SIGHUP labwc");
|
||||||
break;
|
break;
|
||||||
case ACTION_TYPE_SHOW_MENU:
|
case ACTION_TYPE_SHOW_MENU:
|
||||||
show_menu(server, action->arg);
|
show_menu(server, view, action->arg);
|
||||||
break;
|
break;
|
||||||
case ACTION_TYPE_TOGGLE_MAXIMIZE:
|
case ACTION_TYPE_TOGGLE_MAXIMIZE:
|
||||||
if (view) {
|
if (view) {
|
||||||
|
|
|
||||||
|
|
@ -504,6 +504,7 @@ static struct {
|
||||||
{ "W-Right", "SnapToEdge", "right" },
|
{ "W-Right", "SnapToEdge", "right" },
|
||||||
{ "W-Up", "SnapToEdge", "up" },
|
{ "W-Up", "SnapToEdge", "up" },
|
||||||
{ "W-Down", "SnapToEdge", "down" },
|
{ "W-Down", "SnapToEdge", "down" },
|
||||||
|
{ "A-Space", "ShowMenu", "client-menu"},
|
||||||
{ "XF86_AudioLowerVolume", "Execute", "amixer sset Master 5%-" },
|
{ "XF86_AudioLowerVolume", "Execute", "amixer sset Master 5%-" },
|
||||||
{ "XF86_AudioRaiseVolume", "Execute", "amixer sset Master 5%+" },
|
{ "XF86_AudioRaiseVolume", "Execute", "amixer sset Master 5%+" },
|
||||||
{ "XF86_AudioMute", "Execute", "amixer sset Master toggle" },
|
{ "XF86_AudioMute", "Execute", "amixer sset Master toggle" },
|
||||||
|
|
@ -553,6 +554,9 @@ static struct {
|
||||||
{ "Titlebar", "Left", "Press", "Raise", NULL},
|
{ "Titlebar", "Left", "Press", "Raise", NULL},
|
||||||
{ "TitleBar", "Left", "Drag", "Move", NULL },
|
{ "TitleBar", "Left", "Drag", "Move", NULL },
|
||||||
{ "TitleBar", "Left", "DoubleClick", "ToggleMaximize", NULL },
|
{ "TitleBar", "Left", "DoubleClick", "ToggleMaximize", NULL },
|
||||||
|
{ "TitleBar", "Right", "Click", "Focus", NULL},
|
||||||
|
{ "TitleBar", "Right", "Click", "Raise", NULL},
|
||||||
|
{ "TitleBar", "Right", "Click", "ShowMenu", "client-menu"},
|
||||||
{ "Close", "Left", "Click", "Close", NULL },
|
{ "Close", "Left", "Click", "Close", NULL },
|
||||||
{ "Iconify", "Left", "Click", "Iconify", NULL},
|
{ "Iconify", "Left", "Click", "Iconify", NULL},
|
||||||
{ "Maximize", "Left", "Click", "ToggleMaximize", NULL},
|
{ "Maximize", "Left", "Click", "ToggleMaximize", NULL},
|
||||||
|
|
|
||||||
16
src/cursor.c
16
src/cursor.c
|
|
@ -183,7 +183,15 @@ process_cursor_motion(struct server *server, uint32_t time)
|
||||||
process_cursor_resize(server, time);
|
process_cursor_resize(server, time);
|
||||||
return;
|
return;
|
||||||
} else if (server->input_mode == LAB_INPUT_STATE_MENU) {
|
} else if (server->input_mode == LAB_INPUT_STATE_MENU) {
|
||||||
menu_set_selected(server->rootmenu,
|
struct menu *menu = NULL;
|
||||||
|
if (server->rootmenu->visible) {
|
||||||
|
menu = server->rootmenu;
|
||||||
|
} else if (server->windowmenu->visible) {
|
||||||
|
menu = server->windowmenu;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
menu_set_selected(menu,
|
||||||
server->seat.cursor->x, server->seat.cursor->y);
|
server->seat.cursor->x, server->seat.cursor->y);
|
||||||
damage_all_outputs(server);
|
damage_all_outputs(server);
|
||||||
return;
|
return;
|
||||||
|
|
@ -615,7 +623,11 @@ cursor_button(struct wl_listener *listener, void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server->input_mode == LAB_INPUT_STATE_MENU) {
|
if (server->input_mode == LAB_INPUT_STATE_MENU) {
|
||||||
menu_action_selected(server, server->rootmenu);
|
if (server->rootmenu->visible) {
|
||||||
|
menu_action_selected(server, server->rootmenu);
|
||||||
|
} else if (server->windowmenu->visible) {
|
||||||
|
menu_action_selected(server, server->windowmenu);
|
||||||
|
}
|
||||||
server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
|
server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
|
||||||
cursor_rebase(&server->seat, event->time_msec);
|
cursor_rebase(&server->seat, event->time_msec);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ main(int argc, char *argv[])
|
||||||
server.theme = &theme;
|
server.theme = &theme;
|
||||||
|
|
||||||
menu_init_rootmenu(&server);
|
menu_init_rootmenu(&server);
|
||||||
|
menu_init_windowmenu(&server);
|
||||||
|
|
||||||
session_autostart_init();
|
session_autostart_init();
|
||||||
if (startup_cmd) {
|
if (startup_cmd) {
|
||||||
|
|
|
||||||
|
|
@ -313,6 +313,7 @@ menu_init_rootmenu(struct server *server)
|
||||||
|
|
||||||
/* Default menu if no menu.xml found */
|
/* Default menu if no menu.xml found */
|
||||||
if (!server->rootmenu) {
|
if (!server->rootmenu) {
|
||||||
|
current_menu = NULL;
|
||||||
server->rootmenu = menu_create(server, "root-menu", "");
|
server->rootmenu = menu_create(server, "root-menu", "");
|
||||||
}
|
}
|
||||||
if (wl_list_empty(&server->rootmenu->menuitems)) {
|
if (wl_list_empty(&server->rootmenu->menuitems)) {
|
||||||
|
|
@ -326,6 +327,33 @@ menu_init_rootmenu(struct server *server)
|
||||||
menu_configure(server->rootmenu, 100, 100);
|
menu_configure(server->rootmenu, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
menu_init_windowmenu(struct server *server)
|
||||||
|
{
|
||||||
|
server->windowmenu = get_menu_by_id("client-menu");
|
||||||
|
|
||||||
|
/* Default menu if no menu.xml found */
|
||||||
|
if (!server->windowmenu) {
|
||||||
|
current_menu = NULL;
|
||||||
|
server->windowmenu = menu_create(server, "client-menu", "");
|
||||||
|
}
|
||||||
|
if (wl_list_empty(&server->windowmenu->menuitems)) {
|
||||||
|
current_item = item_create(server->windowmenu, "Minimize");
|
||||||
|
fill_item("name.action", "Iconify");
|
||||||
|
current_item = item_create(server->windowmenu, "Maximize");
|
||||||
|
fill_item("name.action", "ToggleMaximize");
|
||||||
|
current_item = item_create(server->windowmenu, "Fullscreen");
|
||||||
|
fill_item("name.action", "ToggleFullscreen");
|
||||||
|
current_item = item_create(server->windowmenu, "Decorations");
|
||||||
|
fill_item("name.action", "ToggleDecorations");
|
||||||
|
current_item = item_create(server->windowmenu, "Close");
|
||||||
|
fill_item("name.action", "Close");
|
||||||
|
}
|
||||||
|
|
||||||
|
server->windowmenu->visible = true;
|
||||||
|
menu_configure(server->windowmenu, 100, 100);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
menu_finish(void)
|
menu_finish(void)
|
||||||
{
|
{
|
||||||
|
|
@ -437,4 +465,5 @@ menu_reconfigure(struct server *server, struct menu *menu)
|
||||||
{
|
{
|
||||||
menu_finish();
|
menu_finish();
|
||||||
menu_init_rootmenu(server);
|
menu_init_rootmenu(server);
|
||||||
|
menu_init_windowmenu(server);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -832,6 +832,7 @@ output_render(struct output *output, pixman_region32_t *damage)
|
||||||
|
|
||||||
if (output->server->input_mode == LAB_INPUT_STATE_MENU) {
|
if (output->server->input_mode == LAB_INPUT_STATE_MENU) {
|
||||||
render_menu(output, damage, server->rootmenu);
|
render_menu(output, damage, server->rootmenu);
|
||||||
|
render_menu(output, damage, server->windowmenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer_end:
|
renderer_end:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue