1 #ifndef XWAYLAND_XWM_H
2 #define XWAYLAND_XWM_H
3 
4 #include <wayland-server-core.h>
5 #include <wlr/config.h>
6 #include <wlr/xwayland.h>
7 #include <xcb/render.h>
8 #if WLR_HAS_XCB_ICCCM
9 #include <xcb/xcb_icccm.h>
10 #endif
11 #if WLR_HAS_XCB_ERRORS
12 #include <xcb/xcb_errors.h>
13 #endif
14 #include "xwayland/selection.h"
15 
16 /* This is in xcb/xcb_event.h, but pulling xcb-util just for a constant
17  * others redefine anyway is meh
18  */
19 #define XCB_EVENT_RESPONSE_TYPE_MASK (0x7f)
20 
21 enum atom_name {
22 	WL_SURFACE_ID,
23 	WM_DELETE_WINDOW,
24 	WM_PROTOCOLS,
25 	WM_HINTS,
26 	WM_NORMAL_HINTS,
27 	WM_SIZE_HINTS,
28 	WM_WINDOW_ROLE,
29 	MOTIF_WM_HINTS,
30 	UTF8_STRING,
31 	WM_S0,
32 	NET_SUPPORTED,
33 	NET_WM_CM_S0,
34 	NET_WM_PID,
35 	NET_WM_NAME,
36 	NET_WM_STATE,
37 	NET_WM_WINDOW_TYPE,
38 	WM_TAKE_FOCUS,
39 	WINDOW,
40 	NET_ACTIVE_WINDOW,
41 	NET_WM_MOVERESIZE,
42 	NET_SUPPORTING_WM_CHECK,
43 	NET_WM_STATE_FOCUSED,
44 	NET_WM_STATE_MODAL,
45 	NET_WM_STATE_FULLSCREEN,
46 	NET_WM_STATE_MAXIMIZED_VERT,
47 	NET_WM_STATE_MAXIMIZED_HORZ,
48 	NET_WM_STATE_HIDDEN,
49 	NET_WM_PING,
50 	WM_CHANGE_STATE,
51 	WM_STATE,
52 	CLIPBOARD,
53 	PRIMARY,
54 	WL_SELECTION,
55 	TARGETS,
56 	CLIPBOARD_MANAGER,
57 	INCR,
58 	TEXT,
59 	TIMESTAMP,
60 	DELETE,
61 	NET_WM_WINDOW_TYPE_NORMAL,
62 	NET_WM_WINDOW_TYPE_UTILITY,
63 	NET_WM_WINDOW_TYPE_TOOLTIP,
64 	NET_WM_WINDOW_TYPE_DND,
65 	NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
66 	NET_WM_WINDOW_TYPE_POPUP_MENU,
67 	NET_WM_WINDOW_TYPE_COMBO,
68 	NET_WM_WINDOW_TYPE_MENU,
69 	NET_WM_WINDOW_TYPE_NOTIFICATION,
70 	NET_WM_WINDOW_TYPE_SPLASH,
71 	DND_SELECTION,
72 	DND_AWARE,
73 	DND_STATUS,
74 	DND_POSITION,
75 	DND_ENTER,
76 	DND_LEAVE,
77 	DND_DROP,
78 	DND_FINISHED,
79 	DND_PROXY,
80 	DND_TYPE_LIST,
81 	DND_ACTION_MOVE,
82 	DND_ACTION_COPY,
83 	DND_ACTION_ASK,
84 	DND_ACTION_PRIVATE,
85 	NET_CLIENT_LIST,
86 	ATOM_LAST // keep last
87 };
88 
89 extern const char *atom_map[ATOM_LAST];
90 
91 enum net_wm_state_action {
92 	NET_WM_STATE_REMOVE = 0,
93 	NET_WM_STATE_ADD = 1,
94 	NET_WM_STATE_TOGGLE = 2,
95 };
96 
97 struct wlr_xwm {
98 	struct wlr_xwayland *xwayland;
99 	struct wl_event_source *event_source;
100 	struct wlr_seat *seat;
101 	uint32_t ping_timeout;
102 
103 	xcb_atom_t atoms[ATOM_LAST];
104 	xcb_connection_t *xcb_conn;
105 	xcb_screen_t *screen;
106 	xcb_window_t window;
107 	xcb_visualid_t visual_id;
108 	xcb_colormap_t colormap;
109 	xcb_render_pictformat_t render_format_id;
110 	xcb_cursor_t cursor;
111 
112 	xcb_window_t selection_window;
113 	struct wlr_xwm_selection clipboard_selection;
114 	struct wlr_xwm_selection primary_selection;
115 
116 	xcb_window_t dnd_window;
117 	struct wlr_xwm_selection dnd_selection;
118 
119 	struct wlr_xwayland_surface *focus_surface;
120 
121 	struct wl_list surfaces; // wlr_xwayland_surface::link
122 	struct wl_list unpaired_surfaces; // wlr_xwayland_surface::unpaired_link
123 
124 	struct wlr_drag *drag;
125 	struct wlr_xwayland_surface *drag_focus;
126 
127 	const xcb_query_extension_reply_t *xfixes;
128 	const xcb_query_extension_reply_t *xwayland_ext;
129 #if WLR_HAS_XCB_ERRORS
130 	xcb_errors_context_t *errors_context;
131 #endif
132 	unsigned int last_focus_seq;
133 
134 	struct wl_listener compositor_new_surface;
135 	struct wl_listener compositor_destroy;
136 	struct wl_listener seat_set_selection;
137 	struct wl_listener seat_set_primary_selection;
138 	struct wl_listener seat_start_drag;
139 	struct wl_listener seat_drag_focus;
140 	struct wl_listener seat_drag_motion;
141 	struct wl_listener seat_drag_drop;
142 	struct wl_listener seat_drag_destroy;
143 	struct wl_listener seat_drag_source_destroy;
144 };
145 
146 struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland, int wm_fd);
147 
148 void xwm_destroy(struct wlr_xwm *xwm);
149 
150 void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride,
151 	uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y);
152 
153 int xwm_handle_selection_event(struct wlr_xwm *xwm, xcb_generic_event_t *event);
154 int xwm_handle_selection_client_message(struct wlr_xwm *xwm,
155 	xcb_client_message_event_t *ev);
156 
157 void xwm_set_seat(struct wlr_xwm *xwm, struct wlr_seat *seat);
158 
159 char *xwm_get_atom_name(struct wlr_xwm *xwm, xcb_atom_t atom);
160 bool xwm_atoms_contains(struct wlr_xwm *xwm, xcb_atom_t *atoms,
161 	size_t num_atoms, enum atom_name needle);
162 
163 void xwm_scale_changed(struct wlr_xwm *xwm);
164 
165 #endif
166