1 /* 2 * Copyright © 2012 Intel Corporation 3 * 4 * 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: 11 * 12 * 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. 24 */ 25 26 #include <stdio.h> 27 #include <wayland-server.h> 28 #include <xcb/xcb.h> 29 #include <xcb/xfixes.h> 30 #include <xcb/composite.h> 31 #include <cairo/cairo-xcb.h> 32 33 #include <libweston/libweston.h> 34 #include <libweston/xwayland-api.h> 35 #include <libweston/weston-log.h> 36 37 #define SEND_EVENT_MASK (0x80) 38 #define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK) 39 40 struct weston_xserver { 41 struct wl_display *wl_display; 42 struct wl_event_loop *loop; 43 int abstract_fd; 44 struct wl_event_source *abstract_source; 45 int unix_fd; 46 struct wl_event_source *unix_source; 47 int display; 48 pid_t pid; 49 struct wl_client *client; 50 struct weston_compositor *compositor; 51 struct weston_wm *wm; 52 struct wl_listener destroy_listener; 53 weston_xwayland_spawn_xserver_func_t spawn_func; 54 void *user_data; 55 56 struct weston_log_scope *wm_debug; 57 }; 58 59 struct weston_wm { 60 xcb_connection_t *conn; 61 const xcb_query_extension_reply_t *xfixes; 62 struct wl_event_source *source; 63 xcb_screen_t *screen; 64 struct hash_table *window_hash; 65 struct weston_xserver *server; 66 xcb_window_t wm_window; 67 struct weston_wm_window *focus_window; 68 struct theme *theme; 69 xcb_cursor_t *cursors; 70 int last_cursor; 71 xcb_render_pictforminfo_t format_rgb, format_rgba; 72 xcb_visualid_t visual_id; 73 xcb_colormap_t colormap; 74 struct wl_listener create_surface_listener; 75 struct wl_listener activate_listener; 76 struct wl_listener kill_listener; 77 struct wl_list unpaired_window_list; 78 79 xcb_window_t selection_window; 80 xcb_window_t selection_owner; 81 int incr; 82 int data_source_fd; 83 struct wl_event_source *property_source; 84 xcb_get_property_reply_t *property_reply; 85 int property_start; 86 struct wl_array source_data; 87 xcb_selection_request_event_t selection_request; 88 xcb_atom_t selection_target; 89 xcb_timestamp_t selection_timestamp; 90 int selection_property_set; 91 int flush_property_on_delete; 92 struct wl_listener selection_listener; 93 94 xcb_window_t dnd_window; 95 xcb_window_t dnd_owner; 96 97 struct { 98 xcb_atom_t wm_protocols; 99 xcb_atom_t wm_normal_hints; 100 xcb_atom_t wm_take_focus; 101 xcb_atom_t wm_delete_window; 102 xcb_atom_t wm_state; 103 xcb_atom_t wm_s0; 104 xcb_atom_t wm_client_machine; 105 xcb_atom_t net_wm_cm_s0; 106 xcb_atom_t net_wm_name; 107 xcb_atom_t net_wm_pid; 108 xcb_atom_t net_wm_icon; 109 xcb_atom_t net_wm_state; 110 xcb_atom_t net_wm_state_maximized_vert; 111 xcb_atom_t net_wm_state_maximized_horz; 112 xcb_atom_t net_wm_state_fullscreen; 113 xcb_atom_t net_wm_user_time; 114 xcb_atom_t net_wm_icon_name; 115 xcb_atom_t net_wm_desktop; 116 xcb_atom_t net_wm_window_type; 117 xcb_atom_t net_wm_window_type_desktop; 118 xcb_atom_t net_wm_window_type_dock; 119 xcb_atom_t net_wm_window_type_toolbar; 120 xcb_atom_t net_wm_window_type_menu; 121 xcb_atom_t net_wm_window_type_utility; 122 xcb_atom_t net_wm_window_type_splash; 123 xcb_atom_t net_wm_window_type_dialog; 124 xcb_atom_t net_wm_window_type_dropdown; 125 xcb_atom_t net_wm_window_type_popup; 126 xcb_atom_t net_wm_window_type_tooltip; 127 xcb_atom_t net_wm_window_type_notification; 128 xcb_atom_t net_wm_window_type_combo; 129 xcb_atom_t net_wm_window_type_dnd; 130 xcb_atom_t net_wm_window_type_normal; 131 xcb_atom_t net_wm_moveresize; 132 xcb_atom_t net_supporting_wm_check; 133 xcb_atom_t net_supported; 134 xcb_atom_t net_active_window; 135 xcb_atom_t motif_wm_hints; 136 xcb_atom_t clipboard; 137 xcb_atom_t clipboard_manager; 138 xcb_atom_t targets; 139 xcb_atom_t utf8_string; 140 xcb_atom_t wl_selection; 141 xcb_atom_t incr; 142 xcb_atom_t timestamp; 143 xcb_atom_t multiple; 144 xcb_atom_t compound_text; 145 xcb_atom_t text; 146 xcb_atom_t string; 147 xcb_atom_t window; 148 xcb_atom_t text_plain_utf8; 149 xcb_atom_t text_plain; 150 xcb_atom_t xdnd_selection; 151 xcb_atom_t xdnd_aware; 152 xcb_atom_t xdnd_enter; 153 xcb_atom_t xdnd_leave; 154 xcb_atom_t xdnd_drop; 155 xcb_atom_t xdnd_status; 156 xcb_atom_t xdnd_finished; 157 xcb_atom_t xdnd_type_list; 158 xcb_atom_t xdnd_action_copy; 159 xcb_atom_t wl_surface_id; 160 xcb_atom_t allow_commits; 161 } atom; 162 }; 163 164 void 165 dump_property(FILE *fp, struct weston_wm *wm, xcb_atom_t property, 166 xcb_get_property_reply_t *reply); 167 168 const char * 169 get_atom_name(xcb_connection_t *c, xcb_atom_t atom); 170 171 void 172 weston_wm_selection_init(struct weston_wm *wm); 173 int 174 weston_wm_handle_selection_event(struct weston_wm *wm, 175 xcb_generic_event_t *event); 176 177 struct weston_wm * 178 weston_wm_create(struct weston_xserver *wxs, int fd); 179 void 180 weston_wm_destroy(struct weston_wm *wm); 181 182 struct weston_seat * 183 weston_wm_pick_seat(struct weston_wm *wm); 184 185 int 186 weston_wm_handle_dnd_event(struct weston_wm *wm, 187 xcb_generic_event_t *event); 188 void 189 weston_wm_dnd_init(struct weston_wm *wm); 190