blob: 54cbf6d6a65faa6e36a59d9ea001e5e31813d73d [file] [log] [blame]
Kristian Høgsberg102bf032012-05-21 15:52:02 -04001/*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#include <wayland-server.h>
24#include <xcb/xcb.h>
25#include <xcb/xfixes.h>
Kristian Høgsbergbcfd07b2013-10-11 16:48:19 -070026#include <xcb/composite.h>
Kristian Høgsberg102bf032012-05-21 15:52:02 -040027#include <cairo/cairo-xcb.h>
28
Kristian Høgsberg2ba10df2013-12-03 16:38:15 -080029#include "compositor.h"
Kristian Høgsberg102bf032012-05-21 15:52:02 -040030
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -070031#define SEND_EVENT_MASK (0x80)
32#define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK)
33
Kristian Høgsberg102bf032012-05-21 15:52:02 -040034struct weston_xserver {
35 struct wl_display *wl_display;
36 struct wl_event_loop *loop;
37 struct wl_event_source *sigchld_source;
38 int abstract_fd;
39 struct wl_event_source *abstract_source;
40 int unix_fd;
41 struct wl_event_source *unix_source;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -070042 int wm_fd;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040043 int display;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -070044 struct wl_event_source *sigusr1_source;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040045 struct weston_process process;
46 struct wl_resource *resource;
47 struct wl_client *client;
48 struct weston_compositor *compositor;
49 struct weston_wm *wm;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040050 struct wl_listener destroy_listener;
51};
52
53struct weston_wm {
54 xcb_connection_t *conn;
55 const xcb_query_extension_reply_t *xfixes;
56 struct wl_event_source *source;
57 xcb_screen_t *screen;
58 struct hash_table *window_hash;
59 struct weston_xserver *server;
60 xcb_window_t wm_window;
61 struct weston_wm_window *focus_window;
62 struct theme *theme;
Tiago Vignatti236b48d2012-07-16 12:09:19 -040063 xcb_cursor_t *cursors;
64 int last_cursor;
Kristian Høgsberge89cef32012-07-16 11:57:08 -040065 xcb_render_pictforminfo_t format_rgb, format_rgba;
Kristian Høgsbergf9187192013-05-02 13:43:24 -040066 xcb_visualid_t visual_id;
67 xcb_colormap_t colormap;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -070068 struct wl_listener create_surface_listener;
Kristian Høgsberge10b1242012-05-21 16:48:05 -040069 struct wl_listener activate_listener;
Tiago Vignattifb2adba2013-06-12 15:43:21 -030070 struct wl_listener transform_listener;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +030071 struct wl_listener kill_listener;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -070072 struct wl_list unpaired_window_list;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040073
74 xcb_window_t selection_window;
Kristian Høgsberg80566732012-06-01 00:08:12 -040075 xcb_window_t selection_owner;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040076 int incr;
77 int data_source_fd;
78 struct wl_event_source *property_source;
79 xcb_get_property_reply_t *property_reply;
80 int property_start;
81 struct wl_array source_data;
82 xcb_selection_request_event_t selection_request;
83 xcb_atom_t selection_target;
84 xcb_timestamp_t selection_timestamp;
85 int selection_property_set;
86 int flush_property_on_delete;
87 struct wl_listener selection_listener;
88
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -070089 xcb_window_t dnd_window;
90 xcb_window_t dnd_owner;
91
Kristian Høgsberg102bf032012-05-21 15:52:02 -040092 struct {
93 xcb_atom_t wm_protocols;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -070094 xcb_atom_t wm_normal_hints;
Kristian Høgsberg102bf032012-05-21 15:52:02 -040095 xcb_atom_t wm_take_focus;
96 xcb_atom_t wm_delete_window;
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -040097 xcb_atom_t wm_state;
Kristian Høgsberg670b5d32012-06-04 11:00:40 -040098 xcb_atom_t wm_s0;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +030099 xcb_atom_t wm_client_machine;
Kristian Høgsberg69981d92013-08-21 22:14:58 -0700100 xcb_atom_t net_wm_cm_s0;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400101 xcb_atom_t net_wm_name;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300102 xcb_atom_t net_wm_pid;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400103 xcb_atom_t net_wm_icon;
104 xcb_atom_t net_wm_state;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +0200105 xcb_atom_t net_wm_state_maximized_vert;
106 xcb_atom_t net_wm_state_maximized_horz;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400107 xcb_atom_t net_wm_state_fullscreen;
108 xcb_atom_t net_wm_user_time;
109 xcb_atom_t net_wm_icon_name;
Giulio Camuffoe90ea442014-12-13 18:06:34 +0200110 xcb_atom_t net_wm_desktop;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400111 xcb_atom_t net_wm_window_type;
112 xcb_atom_t net_wm_window_type_desktop;
113 xcb_atom_t net_wm_window_type_dock;
114 xcb_atom_t net_wm_window_type_toolbar;
115 xcb_atom_t net_wm_window_type_menu;
116 xcb_atom_t net_wm_window_type_utility;
117 xcb_atom_t net_wm_window_type_splash;
118 xcb_atom_t net_wm_window_type_dialog;
119 xcb_atom_t net_wm_window_type_dropdown;
120 xcb_atom_t net_wm_window_type_popup;
121 xcb_atom_t net_wm_window_type_tooltip;
122 xcb_atom_t net_wm_window_type_notification;
123 xcb_atom_t net_wm_window_type_combo;
124 xcb_atom_t net_wm_window_type_dnd;
125 xcb_atom_t net_wm_window_type_normal;
126 xcb_atom_t net_wm_moveresize;
127 xcb_atom_t net_supporting_wm_check;
128 xcb_atom_t net_supported;
129 xcb_atom_t motif_wm_hints;
130 xcb_atom_t clipboard;
Kristian Høgsbergcba022a2012-06-04 10:11:45 -0400131 xcb_atom_t clipboard_manager;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400132 xcb_atom_t targets;
133 xcb_atom_t utf8_string;
134 xcb_atom_t wl_selection;
135 xcb_atom_t incr;
136 xcb_atom_t timestamp;
137 xcb_atom_t multiple;
138 xcb_atom_t compound_text;
139 xcb_atom_t text;
140 xcb_atom_t string;
141 xcb_atom_t text_plain_utf8;
142 xcb_atom_t text_plain;
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -0700143 xcb_atom_t xdnd_selection;
144 xcb_atom_t xdnd_aware;
145 xcb_atom_t xdnd_enter;
146 xcb_atom_t xdnd_leave;
147 xcb_atom_t xdnd_drop;
148 xcb_atom_t xdnd_status;
149 xcb_atom_t xdnd_finished;
150 xcb_atom_t xdnd_type_list;
151 xcb_atom_t xdnd_action_copy;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700152 xcb_atom_t wl_surface_id;
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400153 } atom;
154};
155
156void
157dump_property(struct weston_wm *wm, xcb_atom_t property,
158 xcb_get_property_reply_t *reply);
159
160const char *
161get_atom_name(xcb_connection_t *c, xcb_atom_t atom);
162
Kristian Høgsberg4dec0112012-06-03 09:18:06 -0400163void
164weston_wm_selection_init(struct weston_wm *wm);
Kristian Høgsberg102bf032012-05-21 15:52:02 -0400165int
166weston_wm_handle_selection_event(struct weston_wm *wm,
167 xcb_generic_event_t *event);
168
Kristian Høgsberge10b1242012-05-21 16:48:05 -0400169struct weston_wm *
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700170weston_wm_create(struct weston_xserver *wxs, int fd);
Kristian Høgsberge10b1242012-05-21 16:48:05 -0400171void
172weston_wm_destroy(struct weston_wm *wm);
173
Kristian Høgsberg5ba31892012-08-10 10:06:59 -0400174struct weston_seat *
175weston_wm_pick_seat(struct weston_wm *wm);
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -0700176
177int
178weston_wm_handle_dnd_event(struct weston_wm *wm,
179 xcb_generic_event_t *event);
180void
181weston_wm_dnd_init(struct weston_wm *wm);