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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
|
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <sys/time.h>
#include <wayland-client.h>
#include <xkbcommon/xkbcommon.h>
#include <primary-selection-unstable-v1.h>
#include <presentation-time.h>
#include <tllist.h>
#include "fdm.h"
/* Forward declarations */
struct terminal;
typedef tll(xkb_keycode_t) xkb_keycode_list_t;
struct key_binding {
xkb_mod_mask_t mods;
xkb_keysym_t sym;
xkb_keycode_list_t key_codes;
};
typedef tll(struct key_binding) key_binding_list_t;
enum bind_action_normal {
BIND_ACTION_NONE,
BIND_ACTION_SCROLLBACK_UP_PAGE,
BIND_ACTION_SCROLLBACK_UP_HALF_PAGE,
BIND_ACTION_SCROLLBACK_UP_LINE,
BIND_ACTION_SCROLLBACK_DOWN_PAGE,
BIND_ACTION_SCROLLBACK_DOWN_HALF_PAGE,
BIND_ACTION_SCROLLBACK_DOWN_LINE,
BIND_ACTION_CLIPBOARD_COPY,
BIND_ACTION_CLIPBOARD_PASTE,
BIND_ACTION_PRIMARY_PASTE,
BIND_ACTION_SEARCH_START,
BIND_ACTION_FONT_SIZE_UP,
BIND_ACTION_FONT_SIZE_DOWN,
BIND_ACTION_FONT_SIZE_RESET,
BIND_ACTION_SPAWN_TERMINAL,
BIND_ACTION_MINIMIZE,
BIND_ACTION_MAXIMIZE,
BIND_ACTION_FULLSCREEN,
BIND_ACTION_PIPE_SCROLLBACK,
BIND_ACTION_PIPE_VIEW,
BIND_ACTION_PIPE_SELECTED,
/* Mouse specific actions - i.e. they require a mouse coordinate */
BIND_ACTION_SELECT_BEGIN,
BIND_ACTION_SELECT_BEGIN_BLOCK,
BIND_ACTION_SELECT_EXTEND,
BIND_ACTION_SELECT_WORD,
BIND_ACTION_SELECT_WORD_WS,
BIND_ACTION_SELECT_ROW,
BIND_ACTION_KEY_COUNT = BIND_ACTION_PIPE_SELECTED + 1,
BIND_ACTION_COUNT = BIND_ACTION_SELECT_ROW + 1,
};
struct key_binding_normal {
struct key_binding bind;
enum bind_action_normal action;
char **pipe_argv;
};
struct mouse_binding {
enum bind_action_normal action;
xkb_mod_mask_t mods;
uint32_t button;
int count;
char **pipe_argv;
};
typedef tll(struct mouse_binding) mouse_binding_list_t;
enum bind_action_search {
BIND_ACTION_SEARCH_NONE,
BIND_ACTION_SEARCH_CANCEL,
BIND_ACTION_SEARCH_COMMIT,
BIND_ACTION_SEARCH_FIND_PREV,
BIND_ACTION_SEARCH_FIND_NEXT,
BIND_ACTION_SEARCH_EDIT_LEFT,
BIND_ACTION_SEARCH_EDIT_LEFT_WORD,
BIND_ACTION_SEARCH_EDIT_RIGHT,
BIND_ACTION_SEARCH_EDIT_RIGHT_WORD,
BIND_ACTION_SEARCH_EDIT_HOME,
BIND_ACTION_SEARCH_EDIT_END,
BIND_ACTION_SEARCH_DELETE_PREV,
BIND_ACTION_SEARCH_DELETE_PREV_WORD,
BIND_ACTION_SEARCH_DELETE_NEXT,
BIND_ACTION_SEARCH_DELETE_NEXT_WORD,
BIND_ACTION_SEARCH_EXTEND_WORD,
BIND_ACTION_SEARCH_EXTEND_WORD_WS,
BIND_ACTION_SEARCH_CLIPBOARD_PASTE,
BIND_ACTION_SEARCH_PRIMARY_PASTE,
BIND_ACTION_SEARCH_COUNT,
};
struct key_binding_search {
struct key_binding bind;
enum bind_action_search action;
};
/* Mime-types we support when dealing with data offers (e.g. copy-paste, or DnD) */
enum data_offer_mime_type {
DATA_OFFER_MIME_UNSET,
DATA_OFFER_MIME_TEXT_PLAIN,
DATA_OFFER_MIME_TEXT_UTF8,
DATA_OFFER_MIME_URI_LIST,
};
struct wl_window;
struct wl_clipboard {
struct wl_window *window; /* For DnD */
struct wl_data_source *data_source;
struct wl_data_offer *data_offer;
enum data_offer_mime_type mime_type;
char *text;
uint32_t serial;
};
struct wl_primary {
struct zwp_primary_selection_source_v1 *data_source;
struct zwp_primary_selection_offer_v1 *data_offer;
enum data_offer_mime_type mime_type;
char *text;
uint32_t serial;
};
/* Maps a mouse button to its "owning" surface */
struct button_tracker {
int button;
int surf_kind; /* TODO: this is really an "enum term_surface" */
bool send_to_client; /* Only valid when surface is the main grid surface */
};
struct rect {
int x;
int y;
int width;
int height;
};
struct seat {
struct wayland *wayl;
struct wl_seat *wl_seat;
uint32_t wl_name;
char *name;
/* Focused terminals */
struct terminal *kbd_focus;
struct terminal *mouse_focus;
/* Keyboard state */
struct wl_keyboard *wl_keyboard;
struct {
uint32_t serial;
struct xkb_context *xkb;
struct xkb_keymap *xkb_keymap;
struct xkb_state *xkb_state;
struct xkb_compose_table *xkb_compose_table;
struct xkb_compose_state *xkb_compose_state;
struct {
int fd;
bool dont_re_repeat;
int32_t delay;
int32_t rate;
uint32_t key;
} repeat;
xkb_mod_index_t mod_shift;
xkb_mod_index_t mod_alt;
xkb_mod_index_t mod_ctrl;
xkb_mod_index_t mod_meta;
xkb_keycode_t key_arrow_up;
xkb_keycode_t key_arrow_down;
/* Enabled modifiers */
bool shift;
bool alt;
bool ctrl;
bool meta;
struct {
tll(struct key_binding_normal) key;
tll(struct key_binding_search) search;
} bindings;
} kbd;
/* Pointer state */
struct wl_pointer *wl_pointer;
struct {
uint32_t serial;
struct wl_surface *surface;
struct wl_cursor_theme *theme;
struct wl_cursor *cursor;
int scale;
bool hidden;
const char *xcursor;
struct wl_callback *xcursor_callback;
bool xcursor_pending;
} pointer;
struct {
int x;
int y;
int col;
int row;
/* Mouse buttons currently being pressed, and their "owning" surfaces */
tll(struct button_tracker) buttons;
/* Double- and triple click state */
int count;
int last_released_button;
struct timeval last_time;
/* We used a discrete axis event in the current pointer frame */
double axis_aggregated;
bool have_discrete;
mouse_binding_list_t bindings;
} mouse;
/* Clipboard */
struct wl_data_device *data_device;
struct zwp_primary_selection_device_v1 *primary_selection_device;
struct wl_clipboard clipboard;
struct wl_primary primary;
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
/* Input Method Editor */
struct zwp_text_input_v3 *wl_text_input;
struct {
struct {
struct rect pending;
struct rect sent;
} cursor_rect;
struct {
struct {
char *text;
int32_t cursor_begin;
int32_t cursor_end;
} pending;
} preedit;
struct {
struct {
char *text;
} pending;
} commit;
struct {
struct {
uint32_t before_length;
uint32_t after_length;
} pending;
} surrounding;
uint32_t serial;
} ime;
#endif
};
enum csd_surface {
CSD_SURF_TITLE,
CSD_SURF_LEFT,
CSD_SURF_RIGHT,
CSD_SURF_TOP,
CSD_SURF_BOTTOM,
CSD_SURF_MINIMIZE,
CSD_SURF_MAXIMIZE,
CSD_SURF_CLOSE,
CSD_SURF_COUNT,
};
struct monitor {
struct wayland *wayl;
struct wl_output *output;
struct zxdg_output_v1 *xdg;
uint32_t wl_name;
int x;
int y;
struct {
/* Physical size, in mm */
struct {
int width;
int height;
} mm;
/* Physical size, in pixels */
struct {
int width;
int height;
} px_real;
/* Scaled size, in pixels */
struct {
int width;
int height;
} px_scaled;
} dim;
struct {
/* PPI, based on physical size */
struct {
int x;
int y;
} real;
/* PPI, logical, based on scaled size */
struct {
int x;
int y;
} scaled;
} ppi;
float dpi;
int scale;
float refresh;
enum wl_output_subpixel subpixel;
enum wl_output_transform transform;
/* From wl_output */
char *make;
char *model;
/* From xdg_output */
char *name;
char *description;
float inch; /* e.g. 24" */
bool use_output_release;
};
struct wayland;
struct wl_window {
struct terminal *term;
struct wl_surface *surface;
struct xdg_surface *xdg_surface;
struct xdg_toplevel *xdg_toplevel;
struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration;
enum {CSD_UNKNOWN, CSD_NO, CSD_YES } use_csd;
struct {
struct wl_surface *surface[CSD_SURF_COUNT];
struct wl_subsurface *sub_surface[CSD_SURF_COUNT];
int move_timeout_fd;
uint32_t serial;
} csd;
/* Scrollback search */
struct wl_surface *search_surface;
struct wl_subsurface *search_sub_surface;
struct wl_surface *scrollback_indicator_surface;
struct wl_subsurface *scrollback_indicator_sub_surface;
struct wl_surface *render_timer_surface;
struct wl_subsurface *render_timer_sub_surface;
struct wl_callback *frame_callback;
tll(const struct monitor *) on_outputs; /* Outputs we're mapped on */
bool is_configured;
bool is_fullscreen;
bool is_maximized;
bool is_tiled_top;
bool is_tiled_bottom;
bool is_tiled_left;
bool is_tiled_right;
bool is_tiled; /* At least one of is_tiled_{top,bottom,left,right} is true */
struct {
bool is_activated;
bool is_fullscreen;
bool is_maximized;
bool is_tiled_top;
bool is_tiled_bottom;
bool is_tiled_left;
bool is_tiled_right;
int width;
int height;
} configure;
};
struct config;
struct terminal;
struct wayland {
const struct config *conf;
struct fdm *fdm;
int fd;
struct wl_display *display;
struct wl_registry *registry;
struct wl_compositor *compositor;
struct wl_subcompositor *sub_compositor;
struct wl_shm *shm;
struct zxdg_output_manager_v1 *xdg_output_manager;
struct xdg_wm_base *shell;
struct zxdg_decoration_manager_v1 *xdg_decoration_manager;
struct wl_data_device_manager *data_device_manager;
struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager;
struct wp_presentation *presentation;
uint32_t presentation_clock_id;
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
struct zwp_text_input_manager_v3 *text_input_manager;
#endif
bool have_argb8888;
tll(struct monitor) monitors; /* All available outputs */
tll(struct seat) seats;
tll(struct terminal *) terms;
};
struct wayland *wayl_init(const struct config *conf, struct fdm *fdm);
void wayl_destroy(struct wayland *wayl);
void wayl_flush(struct wayland *wayl);
void wayl_roundtrip(struct wayland *wayl);
struct wl_window *wayl_win_init(struct terminal *term);
void wayl_win_destroy(struct wl_window *win);
bool wayl_reload_xcursor_theme(struct seat *seat, int new_scale);
|