summaryrefslogtreecommitdiffstats
path: root/source/platform/platform_linux.h
blob: d5710fd13afc076af7d48e4caf3a99ab226648f9 (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
60
61
#ifndef PLATFORM_LINUX_H
#define PLATFORM_LINUX_H

// NOTE: one linux binary, two backends picked at runtime: wayland when a compositor is there,
// x11 otherwise (DESIGN_IT_BACKEND=wayland|x11 forces one). everything above the platform
// layer goes through the Platform* macros below, which dispatch on window->backend.

typedef enum LinuxBackend {
	LINUX_BACKEND_WAYLAND,
	LINUX_BACKEND_X11,
} LinuxBackend;

struct PlatformWindow {
	u32          backend; // LinuxBackend
	WaylandState wayland;
	X11State     x11;
	PlatformRefreshProc *refresh; // unused: neither backend blocks during a resize
	void                *refresh_user;
};

// NOTE: text/uri-list -> PlatformInput.drop_paths, shared by wayland and x11 drops
internal void linux_parse_uri_list(PlatformInput *input, const char *text, u64 size);

internal PlatformWindow     *linux_window_open(Arena *arena, WindowParams params);
internal b32                 linux_window_pump(PlatformWindow *window, PlatformInput *input, s64 timeout_ns, int *extra_fds, u32 extra_count, u32 *ready_mask);
internal void                linux_window_size(PlatformWindow *window, u32 *width, u32 *height, u32 *scale);
internal b32                 linux_window_take_resized(PlatformWindow *window);
internal void                linux_window_close(PlatformWindow *window);
internal void                linux_window_begin_move(PlatformWindow *window);
internal void                linux_window_toggle_maximized(PlatformWindow *window);
internal void                linux_window_request_frame(PlatformWindow *window);
internal void                linux_window_cancel_frame(PlatformWindow *window);
internal b32                 linux_window_frame_ready(PlatformWindow *window);
internal void                linux_window_set_cursor(PlatformWindow *window, PlatformCursor cursor);
internal u64                 linux_window_last_frame_done(PlatformWindow *window);
internal u64                 linux_window_frame_requested(PlatformWindow *window);
internal b32                 linux_window_is_layer(PlatformWindow *window);
internal b32                 linux_window_suspended(PlatformWindow *window);
internal f32                 linux_window_ui_scale(PlatformWindow *window);
internal VulkanSurfaceSource linux_window_surface_source(PlatformWindow *window);

#define PlatformWindowOpen(arena, params)                                linux_window_open(arena, params)
#define PlatformWindowPump(window, input, timeout_ns, fds, count, ready) linux_window_pump(window, input, timeout_ns, fds, count, ready)
#define PlatformWindowLastFrameDone(window)                              linux_window_last_frame_done(window)
#define PlatformWindowFrameRequested(window)                             linux_window_frame_requested(window)
#define PlatformWindowSize(window, w, h, s)                              linux_window_size(window, w, h, s)
#define PlatformWindowTakeResized(window)                                linux_window_take_resized(window)
#define PlatformWindowClose(window)                                      linux_window_close(window)
#define PlatformWindowBeginMove(window)                                  linux_window_begin_move(window)
#define PlatformWindowToggleMaximized(window)                            linux_window_toggle_maximized(window)
#define PlatformWindowRequestFrame(window)                               linux_window_request_frame(window)
#define PlatformWindowCancelFrame(window)                                linux_window_cancel_frame(window)
#define PlatformWindowFrameReady(window)                                 linux_window_frame_ready(window)
#define PlatformWindowIsLayer(window)                                    linux_window_is_layer(window)
#define PlatformWindowSetCursor(window, cursor)                          linux_window_set_cursor(window, cursor)
#define PlatformWindowSuspended(window)                                  linux_window_suspended(window)
#define PlatformWindowUiScale(window)                                    linux_window_ui_scale(window)
#define PlatformWindowSurfaceSource(window)                              linux_window_surface_source(window)
#define PlatformWindowSetRefresh(window, proc, user)                     ((window)->refresh = (proc), (window)->refresh_user = (user))

#endif // PLATFORM_LINUX_H