summaryrefslogtreecommitdiffstats
path: root/source/platform/platform_linux_x11.h
blob: 341ae4b5efdb65ba938d4be200b8a38214c93741 (plain) (blame)
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
#ifndef PLATFORM_LINUX_X11_H
#define PLATFORM_LINUX_X11_H

// NOTE: the x11 fallback for sessions without a wayland compositor (or DESIGN_IT_BACKEND=x11).
// plain xlib: an input method for text, XkbSetDetectableAutoRepeat for clean key repeats,
// core font cursors, XDND v5 for file drops, Xft.dpi for the scale. vulkan presents through
// VK_KHR_xlib_surface, so like wayland we never touch pixels ourselves.

typedef struct X11State X11State;
struct X11State {
	Display *display;
	Window   window;
	Window   root;
	int      screen;
	XIM      im;
	XIC      ic;

	//- atoms
	Atom wm_protocols, wm_delete_window, net_wm_name, net_wm_state, net_wm_state_maximized_vert,
	     net_wm_state_maximized_horz, net_wm_state_above, net_wm_moveresize, net_wm_window_type,
	     net_wm_window_type_utility, motif_wm_hints, utf8_string, net_wm_pid;
	Atom xdnd_aware, xdnd_enter, xdnd_position, xdnd_status, xdnd_leave, xdnd_drop, xdnd_finished,
	     xdnd_selection, xdnd_type_list, xdnd_action_copy, uri_list;

	//- drag and drop
	Window xdnd_source;
	u32    xdnd_version;
	b32    xdnd_accept; // the source offers text/uri-list
	f32    xdnd_x, xdnd_y;

	PlatformInput input;
	u8            keys_down[32]; // keycode bitset, a press of a held key is a repeat
	u32           cursor;
	Cursor        cursors[8];    // by PlatformCursor

	u32 width;  // logical
	u32 height;
	u32 physical_width;
	u32 physical_height;
	u32 scale;
	f32 dpi;
	b32 resized;
	b32 is_layer;
	b32 maximized;
	b32 suspended;
	b32 should_close;

	u64 last_frame_done_ns;
	u64 frame_requested_ns;
};

internal b32  x11_window_open(PlatformWindow *window, WindowParams params);
internal b32  x11_window_pump(PlatformWindow *window, PlatformInput *input, s64 timeout_ns, int *extra_fds, u32 extra_count, u32 *ready_mask);
internal void x11_window_close(PlatformWindow *window);
internal void x11_window_begin_move(PlatformWindow *window);
internal void x11_window_toggle_maximized(PlatformWindow *window);
internal void x11_window_set_cursor(PlatformWindow *window, PlatformCursor cursor);

#endif // PLATFORM_LINUX_X11_H