blob: 289fa5affbeacd33a93aa38e15ea980099da52d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
#include "internal.h"
#include "version.h"
#include "wayland.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
static void
render(const struct bm_menu *menu)
{
struct wayland *wayland = menu->renderer->internal;
bm_wl_window_render(&wayland->window, menu);
wl_display_dispatch(wayland->display);
}
static enum bm_key
poll_key(const struct bm_menu *menu, unsigned int *unicode)
{
struct wayland *wayland = menu->renderer->internal;
assert(wayland && unicode);
*unicode = 0;
if (wayland->input.sym == XKB_KEY_NoSymbol)
return BM_KEY_UNICODE;
*unicode = xkb_state_key_get_utf32(wayland->input.xkb.state, wayland->input.code);
switch (wayland->input.sym) {
case XKB_KEY_Up:
return BM_KEY_UP;
case XKB_KEY_Down:
return BM_KEY_DOWN;
case XKB_KEY_Left:
return BM_KEY_LEFT;
case XKB_KEY_Right:
return BM_KEY_RIGHT;
case XKB_KEY_Home:
return BM_KEY_HOME;
case XKB_KEY_End:
return BM_KEY_END;
case XKB_KEY_SunPageUp:
return BM_KEY_PAGE_UP;
case XKB_KEY_SunPageDown:
return BM_KEY_PAGE_DOWN;
case XKB_KEY_BackSpace:
return BM_KEY_BACKSPACE;
case XKB_KEY_Delete:
return BM_KEY_DELETE;
case XKB_KEY_Tab:
return BM_KEY_TAB;
case XKB_KEY_Insert:
return BM_KEY_SHIFT_RETURN;
case XKB_KEY_Return:
return BM_KEY_RETURN;
case XKB_KEY_Escape:
return BM_KEY_ESCAPE;
default: break;
}
return BM_KEY_UNICODE;
}
static uint32_t
get_displayed_count(const struct bm_menu *menu)
{
struct wayland *wayland = menu->renderer->internal;
assert(wayland);
return wayland->window.height / 12;
}
static void
destructor(struct bm_menu *menu)
{
struct wayland *wayland = menu->renderer->internal;
if (!wayland)
return;
bm_wl_window_destroy(&wayland->window);
bm_wl_registry_destroy(wayland);
if (wayland->display) {
wl_display_flush(wayland->display);
wl_display_disconnect(wayland->display);
}
free(wayland);
menu->renderer->internal = NULL;
}
static bool
constructor(struct bm_menu *menu)
{
struct wayland *wayland;
if (!(menu->renderer->internal = wayland = calloc(1, sizeof(struct wayland))))
goto fail;
if (!(wayland->display = wl_display_connect(NULL)))
goto fail;
if (!(wayland->input.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS)))
goto fail;
if (!bm_wl_registry_register(wayland))
goto fail;
struct wl_surface *surface;
if (!(surface = wl_compositor_create_surface(wayland->compositor)))
goto fail;
if (!bm_wl_window_create(&wayland->window, wayland->shm, wayland->shell, wayland->xdg_shell, surface))
goto fail;
wayland->window.notify.render = bm_cairo_paint;
return true;
fail:
destructor(menu);
return false;
}
extern const char*
register_renderer(struct render_api *api)
{
api->constructor = constructor;
api->destructor = destructor;
api->get_displayed_count = get_displayed_count;
api->poll_key = poll_key;
api->render = render;
api->prioritory = BM_PRIO_GUI;
api->version = BM_VERSION;
return "wayland";
}
/* vim: set ts=8 sw=4 tw=0 :*/
|