26#define G_LOG_DOMAIN "Wayland"
27#pragma GCC diagnostic ignored "-Wunused-variable"
28#pragma GCC diagnostic ignored "-Wunused-parameter"
42#include <glib/gstdio.h>
43#include <wayland-client.h>
44#include <wayland-cursor.h>
45#include <xkbcommon/xkbcommon-compose.h>
46#include <xkbcommon/xkbcommon.h>
48#include <libgwater-wayland.h>
50#include <nkutils-bindings.h>
64#ifdef HAVE_WAYLAND_CURSOR_SHAPE
65#include "cursor-shape-v1-protocol.h"
67#include "keyboard-shortcuts-inhibit-unstable-v1-protocol.h"
68#include "primary-selection-unstable-v1-protocol.h"
69#include "text-input-unstable-v3-protocol.h"
70#include "wlr-layer-shell-unstable-v1-protocol.h"
72#define wayland_output_get_dpi(output, scale, dimension) \
73 ((output)->current.physical_##dimension > 0 && (scale) > 0 \
74 ? round((double)(output)->current.dimension * 25.4 / (scale) / \
75 (output)->current.physical_##dimension) \
80#define WHEEL_DETENT 120
131 int menu_x = 0, menu_y = 0;
138 for (
widget *iter = tb_widget; iter != NULL; iter = iter->
parent) {
148 zwp_text_input_v3_set_cursor_rectangle(text_input, x, y, w, h);
169 if (count < wayland->buffer_count) {
195 struct wl_shm_pool *wl_pool;
196 struct wl_buffer *buffer;
205 stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
207 g_warning(
"cairo stride width calculation failure");
210 size = (size_t)stride * height;
213 gchar *shm_name =
"/rofi-wayland-surface";
214 fd = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0600);
215 shm_unlink(shm_name);
217 g_warning(
"creating a buffer file for %zu B failed: %s", pool_size,
221 if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
225 if (ftruncate(fd, pool_size) < 0) {
230 data = mmap(NULL, pool_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
231 if (data == MAP_FAILED) {
232 g_warning(
"mmap of size %zu failed: %s", pool_size, g_strerror(errno));
240 pool->
size = pool_size;
247 wl_pool = wl_shm_create_pool(
wayland->
shm, fd, pool_size);
252 wl_pool, size * i, width, height, stride, WL_SHM_FORMAT_ARGB8888);
258 wl_shm_pool_destroy(wl_pool);
273 struct wl_surface *wl_surface,
274 struct wl_output *wl_output) {
278 if (output == NULL) {
285 g_debug(
"Auto-detected DPI: %d",
config.
dpi);
288 wl_surface_set_buffer_scale(wl_surface, output->
current.scale);
304 struct wl_surface *wl_surface,
305 struct wl_output *wl_output) {}
329 if (buffer == NULL) {
333 cairo_surface_t *surface;
335 surface = cairo_image_surface_create_for_data(
337 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, pool->
width));
352 cairo_surface_destroy(surface);
364 uint32_t timestamp) {
378 enum wl_keyboard_keymap_format format,
379 int32_t fd, uint32_t size) {
380 if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
385 char *str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
386 if (str == MAP_FAILED) {
391 struct xkb_keymap *keymap = xkb_keymap_new_from_string(
393 XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
394 if (keymap == NULL) {
395 fprintf(stderr,
"Failed to get Keymap for current keyboard device.\n");
398 struct xkb_state *state = xkb_state_new(keymap);
401 "Failed to get state object for current keyboard device.\n");
409 uint32_t serial,
struct wl_surface *surface,
410 struct wl_array *keys) {
416 uint32_t *key, *kend;
417 for (key = keys->data, kend = key + keys->size /
sizeof(*key); key < kend;
420 NK_BINDINGS_KEY_STATE_PRESSED);
426 struct wl_surface *surface) {
434 if (self->
repeat.key == 0) {
435 self->
repeat.source = NULL;
436 return G_SOURCE_REMOVE;
441 NK_BINDINGS_KEY_STATE_PRESS);
445 return G_SOURCE_REMOVE;
454 return G_SOURCE_CONTINUE;
460 if (self->
repeat.key == 0) {
466 NK_BINDINGS_KEY_STATE_PRESS);
470 return G_SOURCE_REMOVE;
477 guint repeat_wait_ms = 30;
478 if (self->
repeat.rate != 0) {
479 repeat_wait_ms = 1000 / self->
repeat.rate;
482 self->
repeat.source = g_main_context_find_source_by_id(NULL, source_id);
486 return G_SOURCE_REMOVE;
490 uint32_t serial, uint32_t time, uint32_t key,
491 enum wl_keyboard_key_state kstate) {
498 xkb_keycode_t keycode = key + 8;
499 if (kstate == WL_KEYBOARD_KEY_STATE_RELEASED) {
500 if (keycode == self->
repeat.key) {
502 if (self->
repeat.source != NULL) {
503 g_source_destroy(self->
repeat.source);
504 self->
repeat.source = NULL;
508 NK_BINDINGS_KEY_STATE_RELEASE);
509 }
else if (kstate == WL_KEYBOARD_KEY_STATE_PRESSED) {
510 gchar *text = nk_bindings_seat_handle_key(
513 if (self->
repeat.source != NULL) {
514 g_source_destroy(self->
repeat.source);
515 self->
repeat.source = NULL;
522 self->
repeat.key = keycode;
525 self->
repeat.source = g_main_context_find_source_by_id(NULL, source_id);
535 uint32_t serial, uint32_t mods_depressed,
536 uint32_t mods_latched,
537 uint32_t mods_locked, uint32_t group) {
540 mods_latched, mods_locked, 0, 0, group);
553 struct wl_keyboard *keyboard,
554 int32_t rate, int32_t delay) {
558 self->
repeat.delay = delay;
559 if (self->
repeat.source != NULL) {
560 g_source_destroy(self->
repeat.source);
561 self->
repeat.source = NULL;
577 struct wl_buffer *buffer;
578 struct wl_cursor_image *image;
591 struct wl_callback *callback,
594static const struct wl_callback_listener
600 struct wl_callback *callback,
622 int menu_x = 0, menu_y = 0, menu_w = 0, menu_h = 0;
628 if (menu_w <= 0 || menu_h <= 0) {
648 NkBindingsMouseButton button = -1;
651 button = NK_BINDINGS_MOUSE_BUTTON_PRIMARY;
654 button = NK_BINDINGS_MOUSE_BUTTON_SECONDARY;
657 button = NK_BINDINGS_MOUSE_BUTTON_MIDDLE;
662 gboolean inside = TRUE;
665 inside = self->
button.
x >= menu_x && self->
button.
x < menu_x + menu_w &&
670 if (capture && !inside) {
688 NK_BINDINGS_BUTTON_STATE_PRESS,
691 if (!capture || inside) {
693 NK_BINDINGS_BUTTON_STATE_RELEASE,
701 if (self->
axis_source == WL_POINTER_AXIS_SOURCE_FINGER ||
702 self->
axis_source == WL_POINTER_AXIS_SOURCE_CONTINUOUS) {
708 gint v120 = self->
wheel.vertical;
710 NK_BINDINGS_SCROLL_AXIS_VERTICAL,
720 gint v120 = self->
wheel.horizontal;
722 NK_BINDINGS_SCROLL_AXIS_HORIZONTAL,
742static struct wl_cursor *
745 static const char *
const default_names[] = {
746 "default",
"left_ptr",
"top_left_arrow",
"left-arrow", NULL};
747 static const char *
const pointer_names[] = {
"pointer",
"hand1", NULL};
748 static const char *
const text_names[] = {
"text",
"xterm", NULL};
750 const char *
const *name;
751 struct wl_cursor *cursor = NULL;
755 name = pointer_names;
761 name = default_names;
764 for (; cursor == NULL && *name != NULL; ++name) {
765 cursor = wl_cursor_theme_get_cursor(theme, *name);
770#ifdef HAVE_WAYLAND_CURSOR_SHAPE
771static enum wp_cursor_shape_device_v1_shape
775 return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER;
777 return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT;
779 return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT;
785#ifdef HAVE_WAYLAND_CURSOR_SHAPE
786 if (seat->cursor_shape_device != NULL) {
787 wp_cursor_shape_device_v1_set_shape(
807 wl_pointer_set_cursor(
814 uint32_t serial,
struct wl_surface *surface,
815 wl_fixed_t x, wl_fixed_t y) {
820#ifdef HAVE_WAYLAND_CURSOR_SHAPE
821 if (
wayland->cursor_shape_manager != NULL) {
822 if (self->cursor_shape_device == NULL) {
823 self->cursor_shape_device = wp_cursor_shape_manager_v1_get_pointer(
824 wayland->cursor_shape_manager, pointer);
838 struct wl_cursor *cursor;
845#ifdef HAVE_WAYLAND_CURSOR_SHAPE
846 if (
wayland->cursor_shape_manager == NULL)
854 if (cursor == NULL) {
855 g_info(
"Failed to load cursor type %d", type);
862 while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&seat)) {
870 uint32_t serial,
struct wl_surface *surface) {
880 uint32_t time, wl_fixed_t x, wl_fixed_t y) {
883 self->
button.
x = wl_fixed_to_int(x);
884 self->
button.
y = wl_fixed_to_int(y);
885 self->
motion.
x = wl_fixed_to_int(x);
886 self->
motion.
y = wl_fixed_to_int(y);
891 uint32_t serial, uint32_t time,
893 enum wl_pointer_button_state state) {
900 self->
button.
pressed = (state == WL_POINTER_BUTTON_STATE_PRESSED);
905 uint32_t time,
enum wl_pointer_axis axis,
910 case WL_POINTER_AXIS_VERTICAL_SCROLL:
913 case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
926 enum wl_pointer_axis_source axis_source) {
934 enum wl_pointer_axis axis) {}
937 struct wl_pointer *pointer,
938 enum wl_pointer_axis axis,
945 case WL_POINTER_AXIS_VERTICAL_SCROLL:
948 case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
954#ifdef WL_POINTER_AXIS_VALUE120_SINCE_VERSION
955static void wayland_pointer_axis120(
void *data,
struct wl_pointer *wl_pointer,
956 enum wl_pointer_axis axis,
961 case WL_POINTER_AXIS_VERTICAL_SCROLL:
962 self->
wheel.vertical += value120;
964 case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
965 self->
wheel.horizontal += value120;
980#ifdef WL_POINTER_AXIS_VALUE120_SINCE_VERSION
981 .axis_value120 = wayland_pointer_axis120,
995#define TOUCH_TAP_SLOP 8
996#define TOUCH_AXIS_LOCK (2 * TOUCH_TAP_SLOP)
997#define TOUCH_SCROLL_STEP 30
1009 uint32_t serial, uint32_t time,
1010 struct wl_surface *surface, int32_t
id,
1011 wl_fixed_t x, wl_fixed_t y) {
1018 self->
touch_x = wl_fixed_to_int(x);
1019 self->
touch_y = wl_fixed_to_int(y);
1032 uint32_t serial, uint32_t time, int32_t
id) {
1058 uint32_t time, int32_t
id, wl_fixed_t x,
1061 gint px, py, dx, dy, step;
1068 px = wl_fixed_to_int(x);
1069 py = wl_fixed_to_int(y);
1089 wheel = &self->
wheel.horizontal;
1093 wheel = &self->
wheel.vertical;
1127 wl_fixed_t major, wl_fixed_t minor) {}
1130 int32_t
id, wl_fixed_t orientation) {}
1152 wl_keyboard_release(self->
keyboard);
1155 if (self->
repeat.source != NULL) {
1156 g_source_destroy(self->
repeat.source);
1157 self->
repeat.source = NULL;
1163#define CLIPBOARD_READ_INCREMENT 1024
1174 GIOCondition condition,
1180 g_io_channel_read_chars(channel, info->
buffer + info->
size,
1183 case G_IO_STATUS_AGAIN:
1186 case G_IO_STATUS_NORMAL: {
1192 g_io_channel_shutdown(channel, FALSE, NULL);
1193 g_io_channel_unref(channel);
1207 if (status == G_IO_STATUS_EOF) {
1212 g_warning(
"Could not read data from clipboard");
1214 g_io_channel_shutdown(channel, FALSE, NULL);
1215 g_io_channel_unref(channel);
1217 if (info->
buffer != NULL) {
1227 GIOChannel *channel = g_io_channel_unix_new(
fd);
1231 g_io_channel_unref(channel);
1242 if (info->
buffer == NULL) {
1243 g_io_channel_unref(channel);
1249 g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR,
1256 const char *mime_type) {}
1259 void *data,
struct wl_data_offer *wl_data_offer, uint32_t source_actions) {}
1262 struct wl_data_offer *wl_data_offer,
1263 uint32_t dnd_action) {}
1272 struct wl_data_device *data_device,
1273 struct wl_data_offer *offer) {
1278 struct wl_data_device *wl_data_device,
1280 struct wl_surface *surface, wl_fixed_t x,
1281 wl_fixed_t y,
struct wl_data_offer *
id) {}
1284 struct wl_data_device *wl_data_device) {}
1287 struct wl_data_device *wl_data_device,
1288 uint32_t time, wl_fixed_t x,
1292 struct wl_data_device *wl_data_device) {}
1298 if (clipboard->
offer != NULL) {
1300 wl_data_offer_destroy(clipboard->
offer);
1302 zwp_primary_selection_offer_v1_destroy(clipboard->
offer);
1305 clipboard->
offer = offer;
1309 struct wl_data_device *data_device,
1310 struct wl_data_offer *offer) {
1325 struct zwp_primary_selection_offer_v1 *offer,
1326 const char *mime_type) {}
1328static const struct zwp_primary_selection_offer_v1_listener
1334 void *data,
struct zwp_primary_selection_device_v1 *data_device,
1335 struct zwp_primary_selection_offer_v1 *offer) {
1336 zwp_primary_selection_offer_v1_add_listener(
1341 void *data,
struct zwp_primary_selection_device_v1 *data_device,
1342 struct zwp_primary_selection_offer_v1 *offer) {
1346static const struct zwp_primary_selection_device_v1_listener
1357#ifdef HAVE_WAYLAND_CURSOR_SHAPE
1358 if (self->cursor_shape_device != NULL) {
1359 wp_cursor_shape_device_v1_destroy(self->cursor_shape_device);
1360 self->cursor_shape_device = NULL;
1364 wl_pointer_release(self->
pointer);
1370 if (self->
touch == NULL) {
1374 wl_touch_release(self->
touch);
1385 wl_seat_release(self->
seat);
1393 uint32_t capabilities) {
1396 if ((capabilities & WL_SEAT_CAPABILITY_KEYBOARD) &&
1401 self->
text_input = zwp_text_input_manager_v3_get_text_input(
1406 }
else if ((!(capabilities & WL_SEAT_CAPABILITY_KEYBOARD)) &&
1411 if ((capabilities & WL_SEAT_CAPABILITY_POINTER) && (self->
pointer == NULL)) {
1414 }
else if ((!(capabilities & WL_SEAT_CAPABILITY_POINTER)) &&
1419 if ((capabilities & WL_SEAT_CAPABILITY_TOUCH) && (self->
touch == NULL)) {
1420 self->
touch = wl_seat_get_touch(self->
seat);
1422 }
else if ((!(capabilities & WL_SEAT_CAPABILITY_TOUCH)) &&
1423 (self->
touch != NULL)) {
1428 self->
data_device = wl_data_device_manager_get_data_device(
1435 zwp_primary_selection_device_manager_v1_get_device(
1437 zwp_primary_selection_device_v1_add_listener(
1447 if (self->
name != NULL) {
1450 self->
name = g_strdup(name);
1460 struct wl_surface *surface) {
1461 zwp_text_input_v3_enable(text_input);
1462 zwp_text_input_v3_set_content_type(text_input,
1463 ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE,
1464 ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL);
1466 zwp_text_input_v3_commit(text_input);
1469 struct wl_surface *surface) {
1470 zwp_text_input_v3_disable(text_input);
1471 zwp_text_input_v3_commit(text_input);
1475 struct zwp_text_input_v3 *text_input,
1476 const char *text, int32_t cursor_begin,
1477 int32_t cursor_end) {
1483 zwp_text_input_v3_commit(text_input);
1487 struct zwp_text_input_v3 *text_input,
1499 zwp_text_input_v3_commit(text_input);
1503 void *data,
struct zwp_text_input_v3 *text_input, uint32_t before_length,
1504 uint32_t after_length) {}
1524 g_debug(
"Output release: %s", self->
name);
1526 if (wl_output_get_version(self->
output) >= WL_OUTPUT_RELEASE_SINCE_VERSION) {
1527 wl_output_release(self->
output);
1529 wl_output_destroy(self->
output);
1539#ifdef WL_OUTPUT_NAME_SINCE_VERSION
1540 GHashTableIter iter;
1543 g_debug(
"Monitor lookup by name : %s", name);
1546 while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&output)) {
1547 if (g_strcmp0(output->
name, name) == 0) {
1552 g_debug(
"Monitor lookup by name failed: %s", name);
1562 if (noutputs == 1) {
1563 GHashTableIter iter;
1566 if (g_hash_table_iter_next(&iter, NULL, (gpointer *)&output)) {
1571 if (output != NULL) {
1583 g_debug(
"Output %s: %" PRIi32
"x%" PRIi32
" (%" PRIi32
"x%" PRIi32
"mm)"
1584 " position %" PRIi32
"x%" PRIi32
" scale %" PRIi32
1585 " transform %" PRIi32,
1593 int32_t x, int32_t y, int32_t width,
1594 int32_t height, int32_t subpixel,
1595 const char *make,
const char *model,
1596 int32_t transform) {
1601 self->
pending.physical_width = width;
1602 self->
pending.physical_height = height;
1603 self->
pending.transform = transform;
1607 enum wl_output_mode flags, int32_t width,
1608 int32_t height, int32_t refresh) {
1609 if (flags & WL_OUTPUT_MODE_CURRENT) {
1612 self->
pending.height = height;
1623#ifdef WL_OUTPUT_NAME_SINCE_VERSION
1624static void wayland_output_name(
void *data,
struct wl_output *output,
1629 self->
name = g_strdup(name);
1633#ifdef WL_OUTPUT_DESCRIPTION_SINCE_VERSION
1634static void wayland_output_description(
void *data,
struct wl_output *output,
1635 const char *name) {}
1643#ifdef WL_OUTPUT_NAME_SINCE_VERSION
1644 .name = wayland_output_name,
1646#ifdef WL_OUTPUT_DESCRIPTION_SINCE_VERSION
1647 .description = wayland_output_description,
1652 struct wl_registry *registry,
1653 uint32_t name,
const char *interface,
1655 g_debug(
"wayland registry: interface %s", interface);
1657 if (g_strcmp0(interface, wl_compositor_interface.name) == 0) {
1660 wl_registry_bind(registry, name, &wl_compositor_interface,
1662 }
else if (g_strcmp0(interface, zwlr_layer_shell_v1_interface.name) == 0) {
1665 wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface,
1667 }
else if (g_strcmp0(
1669 zwp_keyboard_shortcuts_inhibit_manager_v1_interface.name) ==
1673 registry, name, &zwp_keyboard_shortcuts_inhibit_manager_v1_interface,
1675 }
else if (g_strcmp0(interface, wl_shm_interface.name) == 0) {
1677 wayland->
shm = wl_registry_bind(registry, name, &wl_shm_interface,
1679 }
else if (g_strcmp0(interface, wl_seat_interface.name) == 0) {
1681 g_error(
"Minimum version of wayland seat interface is %u, got %u",
1691 seat->
seat = wl_registry_bind(registry, name, &wl_seat_interface, version);
1695 }
else if (g_strcmp0(interface, wl_output_interface.name) == 0) {
1697 g_error(
"Minimum version of wayland output interface is %u, got %u",
1707 wl_registry_bind(registry, name, &wl_output_interface, version);
1714 }
else if (strcmp(interface, wl_data_device_manager_interface.name) == 0) {
1716 wl_registry_bind(registry, name, &wl_data_device_manager_interface, 3);
1717 }
else if (strcmp(interface,
1718 zwp_primary_selection_device_manager_v1_interface.name) ==
1721 registry, name, &zwp_primary_selection_device_manager_v1_interface, 1);
1723#ifdef HAVE_WAYLAND_CURSOR_SHAPE
1724 else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
1726 wayland->cursor_shape_manager = wl_registry_bind(
1727 registry, name, &wp_cursor_shape_manager_v1_interface, 1);
1730 else if (strcmp(interface, zwp_text_input_manager_v3_interface.name) == 0) {
1732 registry, name, &zwp_text_input_manager_v3_interface, 1);
1737 struct wl_registry *registry,
1752#ifdef HAVE_WAYLAND_CURSOR_SHAPE
1753 wp_cursor_shape_manager_v1_destroy(
wayland->cursor_shape_manager);
1754 wayland->cursor_shape_manager = NULL;
1762 zwp_keyboard_shortcuts_inhibit_manager_v1_destroy(
1771 g_assert_not_reached();
1791 GHashTableIter iter;
1795 while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&seat)) {
1800 g_hash_table_iter_remove(&iter);
1807 while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&output)) {
1812 g_hash_table_iter_remove(&iter);
1824 void *data,
struct zwlr_layer_surface_v1 *surface, uint32_t serial,
1825 uint32_t width, uint32_t height) {
1828 zwlr_layer_surface_v1_ack_configure(surface, serial);
1844 struct zwlr_layer_surface_v1 *surface) {
1845 g_debug(
"Layer shell surface closed");
1859 if (state != NULL) {
1864static const struct zwlr_layer_surface_v1_listener
1872 return G_SOURCE_REMOVE;
1885 guint64 cursor_size = 24;
1886 char *env_cursor_size = (
char *)g_getenv(
"XCURSOR_SIZE");
1887 if (env_cursor_size && strlen(env_cursor_size) > 0) {
1888 guint64 size = g_ascii_strtoull(env_cursor_size, NULL, 10);
1889 if (0 < size && size < G_MAXUINT64) {
1893 cursor_size *= scale;
1916 char *display = (
char *)g_getenv(
"WAYLAND_DISPLAY");
1919 g_warning(
"Could not connect to the Wayland compositor");
1930 wayland->
outputs = g_hash_table_new(g_direct_hash, g_direct_equal);
1931 wayland->
seats = g_hash_table_new(g_direct_hash, g_direct_equal);
1933 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
1944 g_error(
"Could not connect to wayland compositor");
1948 g_error(
"Rofi on wayland requires support for the layer shell protocol");
1963 struct wl_output *wlo = NULL;
1964 if (output != NULL) {
1969 uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
1971 layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
1973 layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
1975 layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
1977 layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
1979 layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
1980 g_warning(
"Unknown wayland layer: %s, using default overlay",
1989 ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
1990 ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM |
1991 ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
1992 ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
1995 zwlr_layer_surface_v1_add_listener(
1999 g_debug(
"inhibit shortcuts from compositor");
2000 GHashTableIter iter;
2003 while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&seat)) {
2006 zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts(
2022 if (width != NULL) {
2025 if (height != NULL) {
2039 int y_margin,
int loc) {
2045 uint32_t wlr_anchor = 0;
2049 ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
2052 wlr_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
2056 ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
2059 wlr_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
2062 wlr_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
2063 ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
2066 wlr_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
2070 ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
2073 wlr_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
2082 ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
2086 ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
2096 -y_margin, x_margin);
2123 int is_term = isatty(fileno(stdout));
2124 GHashTableIter iter;
2128 printf(
"Monitor layout:\n");
2129 while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&output)) {
2130 printf(
"%s ID%s: %" PRIu32, is_term ?
color_bold :
"",
2133 printf(
"%s name%s: %s\n", is_term ?
color_bold :
"",
2135 printf(
"%s scale%s: %" PRIi32
"\n", is_term ?
color_bold :
"",
2137 printf(
"%s position%s: %" PRIi32
",%" PRIi32
"\n",
2140 printf(
"%s size%s: %" PRIi32
",%" PRIi32
"\n",
2144 if (output->
current.physical_width > 0 &&
2145 output->
current.physical_height > 0) {
2146 printf(
"%s size%s: %" PRIi32
"mm,%" PRIi32
2147 "mm dpi: %.0f,%.0f\n",
2159 GSpawnChildSetupFunc *child_setup,
2160 gpointer *user_data) {}
2181 if (clipboard->
offer == NULL) {
2186 if (pipe(fds) < 0) {
2191 wl_data_offer_receive(clipboard->
offer,
"text/plain;charset=utf-8", fds[1]);
2193 zwp_primary_selection_offer_v1_receive(clipboard->
offer,
2194 "text/plain;charset=utf-8", fds[1]);
struct _display_proxy display_proxy
struct _workarea workarea
void(*) ClipboardCb(const char *clipboard_data, void *user_data)
char * rofi_force_utf8(const gchar *data, ssize_t length)
int textbox_get_cursor_x_pos(const textbox *tb)
textbox * rofi_view_get_active_text(void)
RofiViewState * rofi_view_get_active(void)
void rofi_view_handle_text(RofiViewState *state, const char *text)
void rofi_view_handle_mouse_motion(RofiViewState *state, gint x, gint y, gboolean find_mouse_target)
unsigned int rofi_view_get_element_pitch(const RofiViewState *state, RofiOrientation orientation)
void rofi_view_frame_callback(void)
void rofi_view_maybe_update(RofiViewState *state)
void rofi_view_set_size(RofiViewState *state, gint width, gint height)
void rofi_view_get_menu_rect(int *x, int *y, int *w, int *h)
void rofi_view_cancel(RofiViewState *state)
void rofi_view_pool_refresh(void)
@ ROFI_ORIENTATION_HORIZONTAL
@ ROFI_ORIENTATION_VERTICAL
struct _wayland_seat::@130336165217246304353033257057143104240023300011 wheel_continuous
widget_motion_event motion
struct zwp_primary_selection_device_v1 * primary_selection_device
struct wl_data_device * data_device
struct _wayland_seat::@306352156145172373145330047014333010267160302355 repeat
enum wl_pointer_axis_source axis_source
struct wl_pointer * pointer
wayland_touch_axis touch_axis
struct wl_keyboard * keyboard
struct zwp_text_input_v3 * text_input
struct _wayland_seat::@334334321164220115172153266060100271117106355075 wheel
widget_button_event button
wayland_buffer_pool * pool
struct wl_buffer * buffer
struct wayland_output::@212022230046232300357165202211167342063011325100 pending
struct wayland_output::@212022230046232300357165202211167342063011325100 current
struct wl_output * output
uint32_t global_names[_WAYLAND_GLOBAL_SIZE]
struct wl_surface * surface
struct zwp_primary_selection_device_manager_v1 * primary_selection_device_manager
struct zwp_keyboard_shortcuts_inhibit_manager_v1 * kb_shortcuts_inhibit_manager
struct zwlr_layer_surface_v1 * wlr_surface
struct wayland_stuff::@022067212206215017315002344121072273217107065030 cursor
struct wl_display * display
struct zwlr_layer_shell_v1 * layer_shell
struct wl_compositor * compositor
NkBindingsSeat * bindings_seat
struct wl_registry * registry
struct wl_data_device_manager * data_device_manager
struct wl_callback * frame_cb
clipboard_data clipboards[2]
struct zwp_text_input_manager_v3 * text_input_manager
GWaterWaylandSource * main_loop_source
GHashTable * seats_by_name
#define WL_LAYER_SHELL_INTERFACE_VERSION
struct _wayland_seat wayland_seat
#define WL_KEYBOARD_SHORTCUTS_INHIBITOR_INTERFACE_VERSION
#define WL_SHM_INTERFACE_VERSION
#define WL_SEAT_INTERFACE_MAX_VERSION
@ WAYLAND_GLOBAL_CURSOR_SHAPE
@ WAYLAND_GLOBAL_LAYER_SHELL
@ WAYLAND_GLOBAL_KEYBOARD_SHORTCUTS_INHIBITOR
@ WAYLAND_GLOBAL_COMPOSITOR
#define WL_SEAT_INTERFACE_MIN_VERSION
#define WL_OUTPUT_INTERFACE_MIN_VERSION
@ WAYLAND_TOUCH_AXIS_VERTICAL
@ WAYLAND_TOUCH_AXIS_NONE
@ WAYLAND_TOUCH_AXIS_UNDECIDED
@ WAYLAND_TOUCH_AXIS_HORIZONTAL
#define WL_OUTPUT_INTERFACE_MAX_VERSION
#define WL_COMPOSITOR_INTERFACE_VERSION
static void data_offer_handle_action(void *data, struct wl_data_offer *wl_data_offer, uint32_t dnd_action)
static void wayland_registry_handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
static gboolean wayland_key_repeat_delay(void *data)
static void wayland_pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, enum wl_pointer_axis axis, wl_fixed_t value)
static void clipboard_handle_selection(enum clipboard_type cb_type, void *offer)
static void wayland_layer_shell_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface)
static void wayland_touch_frame(void *data, struct wl_touch *touch)
static gint wayland_touch_scroll_step(RofiOrientation orientation)
static void wayland_display_dump_monitor_layout(void)
static const struct wl_buffer_listener wayland_buffer_listener
static void wayland_touch_shape(void *data, struct wl_touch *touch, int32_t id, wl_fixed_t major, wl_fixed_t minor)
static void wayland_display_set_input_focus(guint w)
static void text_input_done(void *data, struct zwp_text_input_v3 *text_input, uint32_t serial)
static void data_offer_handle_source_actions(void *data, struct wl_data_offer *wl_data_offer, uint32_t source_actions)
static const struct zwlr_layer_surface_v1_listener wayland_layer_shell_surface_listener
static void wayland_seat_capabilities(void *data, struct wl_seat *seat, uint32_t capabilities)
static void wayland_display_revert_input_focus(void)
static const struct wl_registry_listener wayland_registry_listener
static void wayland_seat_name(void *data, struct wl_seat *seat, const char *name)
static void wayland_buffer_release(void *data, struct wl_buffer *buffer)
static const struct wl_data_device_listener data_device_listener
static void wayland_pointer_send_events(wayland_seat *self)
static void wayland_get_clipboard_data(int cb_type, ClipboardCb callback, void *user_data)
static const struct wl_keyboard_listener wayland_keyboard_listener
static void wayland_surface_destroy(void)
static void wayland_pointer_axis_stop(void *data, struct wl_pointer *pointer, uint32_t time, enum wl_pointer_axis axis)
static void wayland_output_scale(void *data, struct wl_output *output, int32_t scale)
double wayland_get_dpi_estimation(void)
static void wayland_output_done(void *data, struct wl_output *output)
void display_surface_commit(cairo_surface_t *surface)
static void wayland_touch_motion(void *data, struct wl_touch *touch, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y)
static void wayland_display_early_cleanup(void)
static void data_device_handle_drop(void *data, struct wl_data_device *wl_data_device)
#define CLIPBOARD_READ_INCREMENT
static const struct zwp_text_input_v3_listener text_input_listener
static void wayland_touch_orientation(void *data, struct wl_touch *touch, int32_t id, wl_fixed_t orientation)
static const struct wl_callback_listener wayland_frame_wl_callback_listener
static gboolean clipboard_read_data(int fd, ClipboardCb callback, void *user_data)
static wayland_stuff wayland_
static void wayland_pointer_axis_discrete(void *data, struct wl_pointer *pointer, enum wl_pointer_axis axis, int32_t discrete)
static void wayland_keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, enum wl_keyboard_key_state kstate)
static wayland_output * wayland_output_by_name(const char *name)
static void wayland_keyboard_modifiers(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
static void wayland_display_startup_notification(RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data)
cairo_surface_t * display_buffer_pool_get_next_buffer(wayland_buffer_pool *pool)
static void primary_selection_device_handle_selection(void *data, struct zwp_primary_selection_device_v1 *data_device, struct zwp_primary_selection_offer_v1 *offer)
static void data_device_handle_selection(void *data, struct wl_data_device *data_device, struct wl_data_offer *offer)
static const struct wl_data_offer_listener data_offer_listener
gboolean display_get_surface_dimensions(int *width, int *height)
static void wayland_pointer_axis_source(void *data, struct wl_pointer *pointer, enum wl_pointer_axis_source axis_source)
static void data_device_handle_leave(void *data, struct wl_data_device *wl_data_device)
#define TOUCH_SCROLL_STEP
void wayland_display_set_cursor_type(RofiCursorType type)
static gboolean wayland_key_repeat(void *data)
static guint wayland_display_scale(void)
static gboolean wayland_display_late_setup(void)
static void wayland_layer_shell_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t width, uint32_t height)
static gboolean wayland_cursor_reload_theme(guint scale)
static void wayland_output_release(wayland_output *self)
static void data_device_handle_motion(void *data, struct wl_data_device *wl_data_device, uint32_t time, wl_fixed_t x, wl_fixed_t y)
static void wayland_seat_release(wayland_seat *self)
static void wayland_buffer_cleanup(wayland_buffer_pool *self)
static void wayland_keyboard_keymap(void *data, struct wl_keyboard *keyboard, enum wl_keyboard_keymap_format format, int32_t fd, uint32_t size)
static void wayland_surface_protocol_enter(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output)
static const cairo_user_data_key_t wayland_cairo_surface_user_data
static void data_device_handle_data_offer(void *data, struct wl_data_device *data_device, struct wl_data_offer *offer)
static void wayland_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
static void wayland_pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, enum wl_pointer_button_state state)
static void text_input_enter(void *data, struct zwp_text_input_v3 *text_input, struct wl_surface *surface)
static const struct wl_pointer_listener wayland_pointer_listener
static display_proxy display_
static void wayland_cursor_set_image(int i)
static void wayland_cursor_update_for_seat(wayland_seat *seat)
static void wayland_output_geometry(void *data, struct wl_output *output, int32_t x, int32_t y, int32_t width, int32_t height, int32_t subpixel, const char *make, const char *model, int32_t transform)
static void wayland_touch_up(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time, int32_t id)
static struct wl_cursor * rofi_cursor_type_to_wl_cursor(struct wl_cursor_theme *theme, RofiCursorType type)
static void wayland_keyboard_leave(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface)
static void primary_selection_device_handle_data_offer(void *data, struct zwp_primary_selection_device_v1 *data_device, struct zwp_primary_selection_offer_v1 *offer)
static void text_input_commit_string(void *data, struct zwp_text_input_v3 *text_input, const char *text)
static void primary_selection_handle_offer(void *data, struct zwp_primary_selection_offer_v1 *offer, const char *mime_type)
static void update_cursor_rectangle(struct zwp_text_input_v3 *text_input)
void display_buffer_pool_free(wayland_buffer_pool *self)
static void wayland_display_cleanup(void)
static void wayland_pointer_release(wayland_seat *self)
#define wayland_output_get_dpi(output, scale, dimension)
static gboolean wayland_display_setup(GMainLoop *main_loop, NkBindings *bindings)
static void wayland_frame_callback(void *data, struct wl_callback *callback, uint32_t time)
static void data_device_handle_enter(void *data, struct wl_data_device *wl_data_device, uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y, struct wl_data_offer *id)
static void text_input_preedit_string(void *data, struct zwp_text_input_v3 *text_input, const char *text, int32_t cursor_begin, int32_t cursor_end)
static const struct zwp_primary_selection_device_v1_listener primary_selection_device_listener
static void text_input_leave(void *data, struct zwp_text_input_v3 *text_input, struct wl_surface *surface)
static void wayland_touch_down(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time, struct wl_surface *surface, int32_t id, wl_fixed_t x, wl_fixed_t y)
static const struct wl_callback_listener wayland_cursor_frame_wl_callback_listener
static void wayland_keyboard_release(wayland_seat *self)
static void wayland_set_fullscreen_mode(void)
struct _display_buffer_pool wayland_buffer_pool
static const struct wl_touch_listener wayland_touch_listener
static void wayland_pointer_frame(void *data, struct wl_pointer *pointer)
static const struct _view_proxy * wayland_display_view_proxy(void)
static void wayland_keyboard_repeat_info(void *data, struct wl_keyboard *keyboard, int32_t rate, int32_t delay)
static const struct wl_output_listener wayland_output_listener
static const struct wl_surface_listener wayland_surface_interface
static gboolean wayland_error(gpointer user_data)
static const struct wl_seat_listener wayland_seat_listener
static void wayland_keyboard_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys)
static void wayland_cursor_frame_callback(void *data, struct wl_callback *callback, uint32_t time)
static void wayland_pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface)
static const struct zwp_primary_selection_offer_v1_listener primary_selection_offer_listener
static void wayland_output_mode(void *data, struct wl_output *output, enum wl_output_mode flags, int32_t width, int32_t height, int32_t refresh)
static void data_offer_handle_offer(void *data, struct wl_data_offer *offer, const char *mime_type)
static void wayland_touch_release(wayland_seat *self)
void display_set_surface_dimensions(int width, int height, int x_margin, int y_margin, int loc)
static void wayland_touch_cancel(void *data, struct wl_touch *touch)
static gboolean clipboard_read_glib_callback(GIOChannel *channel, GIOCondition condition, gpointer opaque)
wayland_buffer_pool * display_buffer_pool_new(gint width, gint height)
display_proxy *const wayland_proxy
static void text_input_delete_surrounding_text(void *data, struct zwp_text_input_v3 *text_input, uint32_t before_length, uint32_t after_length)
static void wayland_pointer_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
static void wayland_pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y)
static int wayland_display_monitor_active(workarea *mon)
static void wayland_surface_protocol_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output)
const view_proxy * wayland_view_proxy