blob: ca75f5b7c787822ba318ba655985c62e8fb6d7e9 [file] [log] [blame]
Kristian Høgsberg102bf032012-05-21 15:52:02 -04001/*
2 * Copyright © 2012 Intel Corporation
3 *
Bryce Harrington0a007dd2015-06-11 16:22:34 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Kristian Høgsberg102bf032012-05-21 15:52:02 -040011 *
Bryce Harrington0a007dd2015-06-11 16:22:34 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Kristian Høgsberg102bf032012-05-21 15:52:02 -040024 */
25
26#include <wayland-server.h>
27#include <xcb/xcb.h>
28#include <xcb/xfixes.h>
Kristian Høgsbergbcfd07b2013-10-11 16:48:19 -070029#include <xcb/composite.h>
Kristian Høgsberg102bf032012-05-21 15:52:02 -040030#include <cairo/cairo-xcb.h>
31
Kristian Høgsberg2ba10df2013-12-03 16:38:15 -080032#include "compositor.h"
Pekka Paalanen58f98c92016-06-03 16:45:21 +030033#include "compositor/weston.h"
Giulio Camuffo9c764df2016-06-29 11:54:27 +020034#include "xwayland-api.h"
Kristian Høgsberg102bf032012-05-21 15:52:02 -040035
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -070036#define SEND_EVENT_MASK (0x80)
37#define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK)
38
Kristian Høgsberg102bf032012-05-21 15:52:02 -040039struct weston_xserver {
40 struct wl_display *wl_display;
41 struct wl_event_loop *loop;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040042 int abstract_fd;
43 struct wl_event_source *abstract_source;
44 int unix_fd;
45 struct wl_event_source *unix_source;
46 int display;
Giulio Camuffo9c764df2016-06-29 11:54:27 +020047 pid_t pid;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040048 struct wl_client *client;
49 struct weston_compositor *compositor;
50 struct weston_wm *wm;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040051 struct wl_listener destroy_listener;
Giulio Camuffo9c764df2016-06-29 11:54:27 +020052 weston_xwayland_spawn_xserver_func_t spawn_func;
53 void *user_data;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040054};
55
56struct weston_wm {
57 xcb_connection_t *conn;
58 const xcb_query_extension_reply_t *xfixes;
59 struct wl_event_source *source;
60 xcb_screen_t *screen;
61 struct hash_table *window_hash;
62 struct weston_xserver *server;
63 xcb_window_t wm_window;
64 struct weston_wm_window *focus_window;
65 struct theme *theme;
Tiago Vignatti236b48d2012-07-16 12:09:19 -040066 xcb_cursor_t *cursors;
67 int last_cursor;
Kristian Høgsberge89cef32012-07-16 11:57:08 -040068 xcb_render_pictforminfo_t format_rgb, format_rgba;
Kristian Høgsbergf9187192013-05-02 13:43:24 -040069 xcb_visualid_t visual_id;
70 xcb_colormap_t colormap;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -070071 struct wl_listener create_surface_listener;
Kristian Høgsberge10b1242012-05-21 16:48:05 -040072 struct wl_listener activate_listener;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +030073 struct wl_listener kill_listener;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -070074 struct wl_list unpaired_window_list;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040075
76 xcb_window_t selection_window;
Kristian Høgsberg80566732012-06-01 00:08:12 -040077 xcb_window_t selection_owner;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040078 int incr;
79 int data_source_fd;
80 struct wl_event_source *property_source;
81 xcb_get_property_reply_t *property_reply;
82 int property_start;
83 struct wl_array source_data;
84 xcb_selection_request_event_t selection_request;
85 xcb_atom_t selection_target;
86 xcb_timestamp_t selection_timestamp;
87 int selection_property_set;
88 int flush_property_on_delete;
89 struct wl_listener selection_listener;
90
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -070091 xcb_window_t dnd_window;
92 xcb_window_t dnd_owner;
93
Kristian Høgsberg102bf032012-05-21 15:52:02 -040094 struct {
95 xcb_atom_t wm_protocols;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -070096 xcb_atom_t wm_normal_hints;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040097 xcb_atom_t wm_take_focus;
98 xcb_atom_t wm_delete_window;
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -040099 xcb_atom_t wm_state;
Kristian Høgsberg670b5d32012-06-04 11:00:40 -0400100 xcb_atom_t wm_s0;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300101 xcb_atom_t wm_client_machine;
Kristian Høgsberg69981d92013-08-21 22:14:58 -0700102 xcb_atom_t net_wm_cm_s0;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400103 xcb_atom_t net_wm_name;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300104 xcb_atom_t net_wm_pid;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400105 xcb_atom_t net_wm_icon;
106 xcb_atom_t net_wm_state;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +0200107 xcb_atom_t net_wm_state_maximized_vert;
108 xcb_atom_t net_wm_state_maximized_horz;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400109 xcb_atom_t net_wm_state_fullscreen;
110 xcb_atom_t net_wm_user_time;
111 xcb_atom_t net_wm_icon_name;
Giulio Camuffoe90ea442014-12-13 18:06:34 +0200112 xcb_atom_t net_wm_desktop;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400113 xcb_atom_t net_wm_window_type;
114 xcb_atom_t net_wm_window_type_desktop;
115 xcb_atom_t net_wm_window_type_dock;
116 xcb_atom_t net_wm_window_type_toolbar;
117 xcb_atom_t net_wm_window_type_menu;
118 xcb_atom_t net_wm_window_type_utility;
119 xcb_atom_t net_wm_window_type_splash;
120 xcb_atom_t net_wm_window_type_dialog;
121 xcb_atom_t net_wm_window_type_dropdown;
122 xcb_atom_t net_wm_window_type_popup;
123 xcb_atom_t net_wm_window_type_tooltip;
124 xcb_atom_t net_wm_window_type_notification;
125 xcb_atom_t net_wm_window_type_combo;
126 xcb_atom_t net_wm_window_type_dnd;
127 xcb_atom_t net_wm_window_type_normal;
128 xcb_atom_t net_wm_moveresize;
129 xcb_atom_t net_supporting_wm_check;
130 xcb_atom_t net_supported;
Benoit Gschwind1a42ca12015-09-25 21:26:04 +0200131 xcb_atom_t net_active_window;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400132 xcb_atom_t motif_wm_hints;
133 xcb_atom_t clipboard;
Kristian Høgsbergcba022a2012-06-04 10:11:45 -0400134 xcb_atom_t clipboard_manager;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400135 xcb_atom_t targets;
136 xcb_atom_t utf8_string;
137 xcb_atom_t wl_selection;
138 xcb_atom_t incr;
139 xcb_atom_t timestamp;
140 xcb_atom_t multiple;
141 xcb_atom_t compound_text;
142 xcb_atom_t text;
143 xcb_atom_t string;
Benoit Gschwind1a42ca12015-09-25 21:26:04 +0200144 xcb_atom_t window;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400145 xcb_atom_t text_plain_utf8;
146 xcb_atom_t text_plain;
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -0700147 xcb_atom_t xdnd_selection;
148 xcb_atom_t xdnd_aware;
149 xcb_atom_t xdnd_enter;
150 xcb_atom_t xdnd_leave;
151 xcb_atom_t xdnd_drop;
152 xcb_atom_t xdnd_status;
153 xcb_atom_t xdnd_finished;
154 xcb_atom_t xdnd_type_list;
155 xcb_atom_t xdnd_action_copy;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700156 xcb_atom_t wl_surface_id;
Pekka Paalanen7ace8312017-01-18 15:37:58 +0200157 xcb_atom_t allow_commits;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400158 } atom;
159};
160
161void
162dump_property(struct weston_wm *wm, xcb_atom_t property,
163 xcb_get_property_reply_t *reply);
164
165const char *
166get_atom_name(xcb_connection_t *c, xcb_atom_t atom);
167
Kristian Høgsberg4dec0112012-06-03 09:18:06 -0400168void
169weston_wm_selection_init(struct weston_wm *wm);
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400170int
171weston_wm_handle_selection_event(struct weston_wm *wm,
172 xcb_generic_event_t *event);
173
Kristian Høgsberge10b1242012-05-21 16:48:05 -0400174struct weston_wm *
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700175weston_wm_create(struct weston_xserver *wxs, int fd);
Kristian Høgsberge10b1242012-05-21 16:48:05 -0400176void
177weston_wm_destroy(struct weston_wm *wm);
178
Kristian Høgsberg5ba31892012-08-10 10:06:59 -0400179struct weston_seat *
180weston_wm_pick_seat(struct weston_wm *wm);
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -0700181
182int
183weston_wm_handle_dnd_event(struct weston_wm *wm,
184 xcb_generic_event_t *event);
185void
186weston_wm_dnd_init(struct weston_wm *wm);