#define XCURSOR_MOVE "grabbing"
enum cursor_mode {
- LAB_CURSOR_PASSTHROUGH,
+ LAB_CURSOR_PASSTHROUGH = 0,
LAB_CURSOR_MOVE,
LAB_CURSOR_RESIZE,
+ LAB_INPUT_STATE_MENU,
};
struct input {
/* Set when in cycle (alt-tab) mode */
struct view *cycle_view;
+
+ struct menu *rootmenu;
};
struct output {
--- /dev/null
+#ifndef __LABWC_MENU_H
+#define __LABWC_MENU_H
+
+#include <wayland-server.h>
+#include <wlr/render/wlr_renderer.h>
+
+struct menuitem {
+ char *action;
+ char *command;
+ struct wlr_box geo_box;
+ struct wlr_texture *active_texture;
+ struct wlr_texture *inactive_texture;
+ bool selected;
+ struct wl_list link;
+};
+
+struct menu {
+ int x;
+ int y;
+ struct wl_list menuitems;
+};
+
+/* menu_create - create menu */
+void menu_init(struct server *server, struct menu *menu);
+
+/* menu_move - move to position (x, y) */
+void menu_move(struct menu *menu, int x, int y);
+
+/* menu_set_selected - select item at (x, y) */
+void menu_set_selected(struct menu *menu, int x, int y);
+
+/* menu_action_selected - select item at (x, y) */
+void menu_action_selected(struct server *server, struct menu *menu);
+
+#endif /* __LABWC_MENU_H */
desktop_next_view(server, server->cycle_view);
} else if (!strcasecmp(action, "Reconfigure")) {
reconfigure();
- } else if (!strcasecmp(action, "debug-views")) {
+ } else if (!strcasecmp(action, "Debug")) {
dbg_show_views(server);
} else {
warn("action (%s) not supported", action);
#include "labwc.h"
+#include "menu/menu.h"
static void
request_cursor_notify(struct wl_listener *listener, void *data)
} else if (server->cursor_mode == LAB_CURSOR_RESIZE) {
process_cursor_resize(server, time);
return;
+ } else if (server->cursor_mode == LAB_INPUT_STATE_MENU) {
+ menu_set_selected(server->rootmenu,
+ server->seat.cursor->x, server->seat.cursor->y);
+ return;
}
/* Otherwise, find the view under the pointer and send the event along.
double sx, sy;
struct wlr_surface *surface;
int view_area;
- struct view *view =
- desktop_view_at(server, server->seat.cursor->x, server->seat.cursor->y,
- &surface, &sx, &sy, &view_area);
+ struct view *view = desktop_view_at(server, server->seat.cursor->x,
+ server->seat.cursor->y, &surface, &sx, &sy, &view_area);
+
+ /* handle _release_ */
if (event->state == WLR_BUTTON_RELEASED) {
- /* Exit interactive move/resize mode. */
- server->cursor_mode = LAB_CURSOR_PASSTHROUGH;
- } else {
- /* Focus that client if the button was _pressed_ */
- desktop_focus_view(&server->seat, view);
- switch (view_area) {
- case LAB_DECO_BUTTON_CLOSE:
- view->impl->close(view);
- break;
- case LAB_DECO_BUTTON_ICONIFY:
- view_minimize(view);
- break;
- case LAB_DECO_PART_TITLE:
- interactive_begin(view, LAB_CURSOR_MOVE, 0);
- break;
- case LAB_DECO_PART_TOP:
- interactive_begin(view, LAB_CURSOR_RESIZE,
- WLR_EDGE_TOP);
- break;
- case LAB_DECO_PART_RIGHT:
- interactive_begin(view, LAB_CURSOR_RESIZE,
- WLR_EDGE_RIGHT);
- break;
- case LAB_DECO_PART_BOTTOM:
- interactive_begin(view, LAB_CURSOR_RESIZE,
- WLR_EDGE_BOTTOM);
- break;
- case LAB_DECO_PART_LEFT:
- interactive_begin(view, LAB_CURSOR_RESIZE,
- WLR_EDGE_LEFT);
- break;
+ if (server->cursor_mode == LAB_INPUT_STATE_MENU) {
+ return;
}
+ /* Exit interactive move/resize/menu mode. */
+ server->cursor_mode = LAB_CURSOR_PASSTHROUGH;
+ return;
+ }
+
+ if (server->cursor_mode == LAB_INPUT_STATE_MENU) {
+ menu_action_selected(server, server->rootmenu);
+ server->cursor_mode = LAB_CURSOR_PASSTHROUGH;
+ return;
+ }
+
+ /* handle _press_ on desktop */
+ if (!view) {
+ /* launch root-menu */
+ server->cursor_mode = LAB_INPUT_STATE_MENU;
+ menu_move(server->rootmenu, server->seat.cursor->x,
+ server->seat.cursor->y);
+ return;
+ }
+
+
+ /* Handle _press_ on view */
+ desktop_focus_view(&server->seat, view);
+ switch (view_area) {
+ case LAB_DECO_BUTTON_CLOSE:
+ view->impl->close(view);
+ break;
+ case LAB_DECO_BUTTON_ICONIFY:
+ view_minimize(view);
+ break;
+ case LAB_DECO_PART_TITLE:
+ interactive_begin(view, LAB_CURSOR_MOVE, 0);
+ break;
+ case LAB_DECO_PART_TOP:
+ interactive_begin(view, LAB_CURSOR_RESIZE,
+ WLR_EDGE_TOP);
+ break;
+ case LAB_DECO_PART_RIGHT:
+ interactive_begin(view, LAB_CURSOR_RESIZE,
+ WLR_EDGE_RIGHT);
+ break;
+ case LAB_DECO_PART_BOTTOM:
+ interactive_begin(view, LAB_CURSOR_RESIZE,
+ WLR_EDGE_BOTTOM);
+ break;
+ case LAB_DECO_PART_LEFT:
+ interactive_begin(view, LAB_CURSOR_RESIZE,
+ WLR_EDGE_LEFT);
+ break;
}
}
#include "labwc.h"
#include "theme/theme.h"
#include "xbm/xbm.h"
+#include "menu/menu.h"
#include <cairo.h>
#include <pango/pangocairo.h>
theme_read(rc.theme_name);
xbm_load(server.renderer);
+ struct menu menu = { 0 };
+ menu_init(&server, &menu);
+ server.rootmenu = &menu;
+
session_autostart_init();
if (startup_cmd) {
spawn_async_no_shell(startup_cmd);
--- /dev/null
+#define _POSIX_C_SOURCE 200809L
+#include <cairo/cairo.h>
+#include <pango/pangocairo.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "labwc.h"
+#include "menu/menu.h"
+
+static float background[4] = { 0.3f, 0.1f, 0.1f, 1.0f };
+static float foreground[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
+static const char font[] = "Sans 11";
+
+struct wlr_texture *
+texture_create(struct server *server, struct wlr_box *geo, const char *text,
+ float *bg, float *fg)
+{
+ cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+ geo->width, geo->height);
+ cairo_t *cairo = cairo_create(surf);
+
+ cairo_set_source_rgb(cairo, bg[0], bg[1], bg[2]);
+ cairo_paint(cairo);
+ cairo_set_source_rgba(cairo, fg[0], fg[1], fg[2], fg[3]);
+ cairo_move_to(cairo, 0, 0);
+
+ PangoLayout *layout = pango_cairo_create_layout(cairo);
+ pango_layout_set_width(layout, geo->width * PANGO_SCALE);
+ pango_layout_set_text(layout, text, -1);
+
+ PangoFontDescription *desc = pango_font_description_from_string(font);
+ pango_layout_set_font_description(layout, desc);
+ pango_font_description_free(desc);
+ pango_cairo_update_layout(cairo, layout);
+ pango_cairo_show_layout(cairo, layout);
+ g_object_unref(layout);
+
+ cairo_surface_flush(surf);
+ unsigned char *data = cairo_image_surface_get_data(surf);
+ struct wlr_texture *texture = wlr_texture_from_pixels(server->renderer,
+ WL_SHM_FORMAT_ARGB8888, cairo_image_surface_get_stride(surf),
+ geo->width, geo->height, data);
+
+ cairo_destroy(cairo);
+ cairo_surface_destroy(surf);
+ return texture;
+}
+
+#define MENUWIDTH (100)
+#define MENUHEIGHT (25)
+
+struct menuitem *
+menuitem_create(struct server *server, struct menu *menu, const char *text,
+ const char *action, const char *command)
+{
+ struct menuitem *menuitem = calloc(1, sizeof(struct menuitem));
+ if (!menuitem) {
+ return NULL;
+ }
+ menuitem->action = action ? strdup(action) : NULL;
+ menuitem->command = command ? strdup(command) : NULL;
+ menuitem->geo_box.width = MENUWIDTH;
+ menuitem->geo_box.height = MENUHEIGHT;
+ menuitem->active_texture = texture_create(server, &menuitem->geo_box,
+ text, background, foreground);
+ menuitem->inactive_texture = texture_create(server, &menuitem->geo_box,
+ text, foreground, background);
+ wl_list_insert(&menu->menuitems, &menuitem->link);
+ return menuitem;
+}
+
+void
+menu_init(struct server *server, struct menu *menu)
+{
+ wl_list_init(&menu->menuitems);
+ menuitem_create(server, menu, "Terminal", "Execute", "sakura");
+ menuitem_create(server, menu, "Reconfigure", "Reconfigure", NULL);
+ menuitem_create(server, menu, "Exit", "Exit", NULL);
+ menu_move(menu, 100, 100);
+}
+
+void
+menu_move(struct menu *menu, int x, int y)
+{
+ menu->x = x;
+ menu->y = y;
+
+ int offset = 0;
+ struct menuitem *menuitem;
+ wl_list_for_each (menuitem, &menu->menuitems, link) {
+ menuitem->geo_box.x = menu->x;
+ menuitem->geo_box.y = menu->y + offset;
+ offset += menuitem->geo_box.height;
+ }
+}
+
+void
+menu_set_selected(struct menu *menu, int x, int y)
+{
+ struct menuitem *menuitem;
+ wl_list_for_each (menuitem, &menu->menuitems, link) {
+ menuitem->selected =
+ wlr_box_contains_point(&menuitem->geo_box, x, y);
+ }
+}
+
+void
+menu_action_selected(struct server *server, struct menu *menu)
+{
+ struct menuitem *menuitem;
+ wl_list_for_each (menuitem, &menu->menuitems, link) {
+ if (menuitem->selected) {
+ action(server, menuitem->action, menuitem->command);
+ break;
+ }
+ }
+}
--- /dev/null
+labwc_sources += files(
+ 'menu.c',
+)
subdir('config')
subdir('theme')
subdir('xbm')
+subdir('menu')
#define _POSIX_C_SOURCE 200809L
#include <wlr/types/wlr_xdg_output_v1.h>
#include "labwc.h"
+#include "menu/menu.h"
#include "theme/theme.h"
#include "layers.h"
draw_rect_unfilled(&dd, box);
}
+static void
+render_rootmenu(struct output *output)
+{
+ struct server *server = output->server;
+ struct draw_data ddata = {
+ .renderer = server->renderer,
+ .transform_matrix = output->wlr_output->transform_matrix,
+ };
+ float matrix[9];
+
+ ddata.rgba = (float[4]){ 0.9, 0.3, 0.3, 0.5 };
+ struct menuitem *menuitem;
+ wl_list_for_each (menuitem, &server->rootmenu->menuitems, link) {
+ struct wlr_texture *t;
+ t = menuitem->selected ? menuitem->active_texture :
+ menuitem->inactive_texture;
+ wlr_matrix_project_box(matrix, &menuitem->geo_box,
+ WL_OUTPUT_TRANSFORM_NORMAL, 0, ddata.transform_matrix);
+ wlr_render_texture_with_matrix(ddata.renderer, t, matrix, 1);
+ }
+
+}
+
static void
render_icon(struct draw_data *d, struct wlr_box box,
struct wlr_texture *texture)
render_layer(&now, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
render_layer(&now, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
+
+ if (output->server->cursor_mode == LAB_INPUT_STATE_MENU) {
+ render_rootmenu(output);
+ }
+
/* Just in case hardware cursors not supported by GPU */
wlr_output_render_software_cursors(output->wlr_output, NULL);