xdg-shell stable: copy-pasta implementation
This commit is contained in:
parent
71cba94e73
commit
7d26a6debd
|
@ -15,6 +15,7 @@
|
|||
#include <wlr/types/wlr_wl_shell.h>
|
||||
#include <wlr/types/wlr_xcursor_manager.h>
|
||||
#include <wlr/types/wlr_xdg_shell_v6.h>
|
||||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include "rootston/config.h"
|
||||
#include "rootston/output.h"
|
||||
#include "rootston/view.h"
|
||||
|
@ -34,6 +35,7 @@ struct roots_desktop {
|
|||
struct wlr_compositor *compositor;
|
||||
struct wlr_wl_shell *wl_shell;
|
||||
struct wlr_xdg_shell_v6 *xdg_shell_v6;
|
||||
struct wlr_xdg_shell *xdg_shell;
|
||||
struct wlr_gamma_control_manager *gamma_control_manager;
|
||||
struct wlr_screenshooter *screenshooter;
|
||||
struct wlr_server_decoration_manager *server_decoration_manager;
|
||||
|
@ -43,6 +45,7 @@ struct roots_desktop {
|
|||
struct wl_listener new_output;
|
||||
struct wl_listener layout_change;
|
||||
struct wl_listener xdg_shell_v6_surface;
|
||||
struct wl_listener xdg_shell_surface;
|
||||
struct wl_listener wl_shell_surface;
|
||||
struct wl_listener decoration_new;
|
||||
|
||||
|
@ -72,6 +75,7 @@ void view_update_position(struct roots_view *view, double x, double y);
|
|||
void view_update_size(struct roots_view *view, uint32_t width, uint32_t height);
|
||||
|
||||
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data);
|
||||
void handle_xdg_shell_surface(struct wl_listener *listener, void *data);
|
||||
void handle_wl_shell_surface(struct wl_listener *listener, void *data);
|
||||
void handle_xwayland_surface(struct wl_listener *listener, void *data);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/types/wlr_xdg_shell_v6.h>
|
||||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
|
||||
struct roots_wl_shell_surface {
|
||||
struct roots_view *view;
|
||||
|
@ -36,6 +37,21 @@ struct roots_xdg_surface_v6 {
|
|||
uint32_t pending_move_resize_configure_serial;
|
||||
};
|
||||
|
||||
struct roots_xdg_surface {
|
||||
struct roots_view *view;
|
||||
|
||||
struct wl_listener destroy;
|
||||
struct wl_listener new_popup;
|
||||
struct wl_listener request_move;
|
||||
struct wl_listener request_resize;
|
||||
struct wl_listener request_maximize;
|
||||
struct wl_listener request_fullscreen;
|
||||
|
||||
struct wl_listener surface_commit;
|
||||
|
||||
uint32_t pending_move_resize_configure_serial;
|
||||
};
|
||||
|
||||
struct roots_xwayland_surface {
|
||||
struct roots_view *view;
|
||||
|
||||
|
@ -54,6 +70,7 @@ struct roots_xwayland_surface {
|
|||
enum roots_view_type {
|
||||
ROOTS_WL_SHELL_VIEW,
|
||||
ROOTS_XDG_SHELL_V6_VIEW,
|
||||
ROOTS_XDG_SHELL_VIEW,
|
||||
#ifdef WLR_HAS_XWAYLAND
|
||||
ROOTS_XWAYLAND_VIEW,
|
||||
#endif
|
||||
|
@ -90,6 +107,7 @@ struct roots_view {
|
|||
union {
|
||||
struct wlr_wl_shell_surface *wl_shell_surface;
|
||||
struct wlr_xdg_surface_v6 *xdg_surface_v6;
|
||||
struct wlr_xdg_surface *xdg_surface;
|
||||
#ifdef WLR_HAS_XWAYLAND
|
||||
struct wlr_xwayland_surface *xwayland_surface;
|
||||
#endif
|
||||
|
@ -97,6 +115,7 @@ struct roots_view {
|
|||
union {
|
||||
struct roots_wl_shell_surface *roots_wl_shell_surface;
|
||||
struct roots_xdg_surface_v6 *roots_xdg_surface_v6;
|
||||
struct roots_xdg_surface *roots_xdg_surface;
|
||||
#ifdef WLR_HAS_XWAYLAND
|
||||
struct roots_xwayland_surface *roots_xwayland_surface;
|
||||
#endif
|
||||
|
@ -154,6 +173,13 @@ struct roots_xdg_popup_v6 {
|
|||
struct wl_listener new_popup;
|
||||
};
|
||||
|
||||
struct roots_xdg_popup {
|
||||
struct roots_view_child view_child;
|
||||
struct wlr_xdg_popup *wlr_popup;
|
||||
struct wl_listener destroy;
|
||||
struct wl_listener new_popup;
|
||||
};
|
||||
|
||||
void view_get_box(const struct roots_view *view, struct wlr_box *box);
|
||||
void view_activate(struct roots_view *view, bool active);
|
||||
void view_move(struct roots_view *view, double x, double y);
|
||||
|
|
|
@ -0,0 +1,232 @@
|
|||
#ifndef WLR_TYPES_WLR_XDG_SHELL_H
|
||||
#define WLR_TYPES_WLR_XDG_SHELL_H
|
||||
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_seat.h>
|
||||
#include <wayland-server.h>
|
||||
|
||||
struct wlr_xdg_shell {
|
||||
struct wl_global *wl_global;
|
||||
struct wl_list clients;
|
||||
struct wl_list popup_grabs;
|
||||
uint32_t ping_timeout;
|
||||
|
||||
struct wl_listener display_destroy;
|
||||
|
||||
struct {
|
||||
struct wl_signal new_surface;
|
||||
} events;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct wlr_xdg_client {
|
||||
struct wlr_xdg_shell *shell;
|
||||
struct wl_resource *resource;
|
||||
struct wl_client *client;
|
||||
struct wl_list surfaces;
|
||||
|
||||
struct wl_list link; // wlr_xdg_shell::clients
|
||||
|
||||
uint32_t ping_serial;
|
||||
struct wl_event_source *ping_timer;
|
||||
};
|
||||
|
||||
struct wlr_xdg_popup {
|
||||
struct wlr_xdg_surface *base;
|
||||
struct wl_list link;
|
||||
|
||||
struct wl_resource *resource;
|
||||
bool committed;
|
||||
struct wlr_xdg_surface *parent;
|
||||
struct wlr_seat *seat;
|
||||
struct wlr_box geometry;
|
||||
|
||||
struct wl_list grab_link; // wlr_xdg_popup_grab::popups
|
||||
};
|
||||
|
||||
// each seat gets a popup grab
|
||||
struct wlr_xdg_popup_grab {
|
||||
struct wl_client *client;
|
||||
struct wlr_seat_pointer_grab pointer_grab;
|
||||
struct wlr_seat_keyboard_grab keyboard_grab;
|
||||
struct wlr_seat *seat;
|
||||
struct wl_list popups;
|
||||
struct wl_list link; // wlr_xdg_shell::popup_grabs
|
||||
};
|
||||
|
||||
enum wlr_xdg_surface_role {
|
||||
WLR_XDG_SURFACE_ROLE_NONE,
|
||||
WLR_XDG_SURFACE_ROLE_TOPLEVEL,
|
||||
WLR_XDG_SURFACE_ROLE_POPUP,
|
||||
};
|
||||
|
||||
struct wlr_xdg_toplevel_state {
|
||||
bool maximized;
|
||||
bool fullscreen;
|
||||
bool resizing;
|
||||
bool activated;
|
||||
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
||||
uint32_t max_width;
|
||||
uint32_t max_height;
|
||||
|
||||
uint32_t min_width;
|
||||
uint32_t min_height;
|
||||
};
|
||||
|
||||
struct wlr_xdg_toplevel {
|
||||
struct wl_resource *resource;
|
||||
struct wlr_xdg_surface *base;
|
||||
struct wlr_xdg_surface *parent;
|
||||
bool added;
|
||||
struct wlr_xdg_toplevel_state next; // client protocol requests
|
||||
struct wlr_xdg_toplevel_state pending; // user configure requests
|
||||
struct wlr_xdg_toplevel_state current;
|
||||
};
|
||||
|
||||
struct wlr_xdg_surface_configure {
|
||||
struct wl_list link; // wlr_xdg_surface::configure_list
|
||||
uint32_t serial;
|
||||
struct wlr_xdg_toplevel_state state;
|
||||
};
|
||||
|
||||
struct wlr_xdg_surface {
|
||||
struct wlr_xdg_client *client;
|
||||
struct wl_resource *resource;
|
||||
struct wlr_surface *surface;
|
||||
struct wl_list link; // wlr_xdg_client::surfaces
|
||||
enum wlr_xdg_surface_role role;
|
||||
|
||||
union {
|
||||
struct wlr_xdg_toplevel *toplevel_state;
|
||||
struct wlr_xdg_popup *popup_state;
|
||||
};
|
||||
|
||||
struct wl_list popups; // wlr_xdg_popup::link
|
||||
|
||||
bool configured;
|
||||
bool added;
|
||||
uint32_t configure_serial;
|
||||
struct wl_event_source *configure_idle;
|
||||
uint32_t configure_next_serial;
|
||||
struct wl_list configure_list;
|
||||
|
||||
char *title;
|
||||
char *app_id;
|
||||
|
||||
bool has_next_geometry;
|
||||
struct wlr_box *next_geometry;
|
||||
struct wlr_box *geometry;
|
||||
|
||||
struct wl_listener surface_destroy_listener;
|
||||
|
||||
struct {
|
||||
struct wl_signal destroy;
|
||||
struct wl_signal ping_timeout;
|
||||
struct wl_signal new_popup;
|
||||
|
||||
struct wl_signal request_maximize;
|
||||
struct wl_signal request_fullscreen;
|
||||
struct wl_signal request_minimize;
|
||||
struct wl_signal request_move;
|
||||
struct wl_signal request_resize;
|
||||
struct wl_signal request_show_window_menu;
|
||||
} events;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct wlr_xdg_toplevel_move_event {
|
||||
struct wlr_xdg_surface *surface;
|
||||
struct wlr_seat_client *seat;
|
||||
uint32_t serial;
|
||||
};
|
||||
|
||||
struct wlr_xdg_toplevel_resize_event {
|
||||
struct wlr_xdg_surface *surface;
|
||||
struct wlr_seat_client *seat;
|
||||
uint32_t serial;
|
||||
uint32_t edges;
|
||||
};
|
||||
|
||||
struct wlr_xdg_toplevel_set_fullscreen_event {
|
||||
struct wlr_xdg_surface *surface;
|
||||
bool fullscreen;
|
||||
struct wlr_output *output;
|
||||
};
|
||||
|
||||
struct wlr_xdg_toplevel_show_window_menu_event {
|
||||
struct wlr_xdg_surface *surface;
|
||||
struct wlr_seat_client *seat;
|
||||
uint32_t serial;
|
||||
uint32_t x, y;
|
||||
};
|
||||
|
||||
struct wlr_xdg_shell *wlr_xdg_shell_create(struct wl_display *display);
|
||||
void wlr_xdg_shell_destroy(struct wlr_xdg_shell *xdg_shell);
|
||||
|
||||
/**
|
||||
* Send a ping to the surface. If the surface does not respond in a reasonable
|
||||
* amount of time, the ping_timeout event will be emitted.
|
||||
*/
|
||||
void wlr_xdg_surface_ping(struct wlr_xdg_surface *surface);
|
||||
|
||||
/**
|
||||
* Request that this toplevel surface be the given size. Returns the associated
|
||||
* configure serial.
|
||||
*/
|
||||
uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface,
|
||||
uint32_t width, uint32_t height);
|
||||
|
||||
/**
|
||||
* Request that this toplevel surface show itself in an activated or deactivated
|
||||
* state. Returns the associated configure serial.
|
||||
*/
|
||||
uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface,
|
||||
bool activated);
|
||||
|
||||
/**
|
||||
* Request that this toplevel surface consider itself maximized or not
|
||||
* maximized. Returns the associated configure serial.
|
||||
*/
|
||||
uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface,
|
||||
bool maximized);
|
||||
|
||||
/**
|
||||
* Request that this toplevel surface consider itself fullscreen or not
|
||||
* fullscreen. Returns the associated configure serial.
|
||||
*/
|
||||
uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface,
|
||||
bool fullscreen);
|
||||
|
||||
/**
|
||||
* Request that this toplevel surface consider itself to be resizing or not
|
||||
* resizing. Returns the associated configure serial.
|
||||
*/
|
||||
uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_surface *surface,
|
||||
bool resizing);
|
||||
|
||||
/**
|
||||
* Request that this toplevel surface closes.
|
||||
*/
|
||||
void wlr_xdg_toplevel_send_close(struct wlr_xdg_surface *surface);
|
||||
|
||||
/**
|
||||
* Compute the popup position in surface-local coordinates.
|
||||
*/
|
||||
void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface,
|
||||
double *popup_sx, double *popup_sy);
|
||||
|
||||
/**
|
||||
* Find a popup within this surface at the surface-local coordinates. Returns
|
||||
* the popup and coordinates in the topmost surface coordinate system or NULL if
|
||||
* no popup is found at that location.
|
||||
*/
|
||||
struct wlr_xdg_surface *wlr_xdg_surface_popup_at(
|
||||
struct wlr_xdg_surface *surface, double sx, double sy,
|
||||
double *popup_sx, double *popup_sy);
|
||||
|
||||
#endif
|
|
@ -22,6 +22,7 @@ wayland_scanner_client = generator(
|
|||
|
||||
protocols = [
|
||||
[wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'],
|
||||
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
|
||||
'gamma-control.xml',
|
||||
'gtk-primary-selection.xml',
|
||||
'idle.xml',
|
||||
|
@ -31,6 +32,7 @@ protocols = [
|
|||
|
||||
client_protocols = [
|
||||
[wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'],
|
||||
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
|
||||
'gamma-control.xml',
|
||||
'gtk-primary-selection.xml',
|
||||
'idle.xml',
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <wlr/types/wlr_wl_shell.h>
|
||||
#include <wlr/types/wlr_xcursor_manager.h>
|
||||
#include <wlr/types/wlr_xdg_shell_v6.h>
|
||||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "rootston/seat.h"
|
||||
#include "rootston/server.h"
|
||||
|
@ -639,6 +640,11 @@ struct roots_desktop *desktop_create(struct roots_server *server,
|
|||
&desktop->xdg_shell_v6_surface);
|
||||
desktop->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface;
|
||||
|
||||
desktop->xdg_shell = wlr_xdg_shell_create(server->wl_display);
|
||||
wl_signal_add(&desktop->xdg_shell->events.new_surface,
|
||||
&desktop->xdg_shell_surface);
|
||||
desktop->xdg_shell_surface.notify = handle_xdg_shell_surface;
|
||||
|
||||
desktop->wl_shell = wlr_wl_shell_create(server->wl_display);
|
||||
wl_signal_add(&desktop->wl_shell->events.new_surface,
|
||||
&desktop->wl_shell_surface);
|
||||
|
|
|
@ -10,6 +10,7 @@ sources = [
|
|||
'seat.c',
|
||||
'wl_shell.c',
|
||||
'xdg_shell_v6.c',
|
||||
'xdg_shell.c',
|
||||
]
|
||||
if get_option('enable_xwayland')
|
||||
sources += ['xwayland.c']
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include <wlr/types/wlr_wl_shell.h>
|
||||
#include <wlr/types/wlr_xdg_shell_v6.h>
|
||||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/util/region.h>
|
||||
#include "rootston/config.h"
|
||||
|
@ -81,6 +82,34 @@ static void xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface,
|
|||
}
|
||||
}
|
||||
|
||||
static void xdg_surface_for_each_surface(struct wlr_xdg_surface *surface,
|
||||
double base_x, double base_y, float rotation,
|
||||
surface_iterator_func_t iterator, void *user_data) {
|
||||
double width = surface->surface->current->width;
|
||||
double height = surface->surface->current->height;
|
||||
|
||||
struct wlr_xdg_popup *popup_state;
|
||||
wl_list_for_each(popup_state, &surface->popups, link) {
|
||||
struct wlr_xdg_surface *popup = popup_state->base;
|
||||
if (!popup->configured) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double popup_width = popup->surface->current->width;
|
||||
double popup_height = popup->surface->current->height;
|
||||
|
||||
double popup_sx, popup_sy;
|
||||
wlr_xdg_surface_popup_get_position(popup, &popup_sx, &popup_sy);
|
||||
rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height,
|
||||
width, height, rotation);
|
||||
|
||||
surface_for_each_surface(popup->surface, base_x + popup_sx,
|
||||
base_y + popup_sy, rotation, iterator, user_data);
|
||||
xdg_surface_for_each_surface(popup, base_x + popup_sx,
|
||||
base_y + popup_sy, rotation, iterator, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void wl_shell_surface_for_each_surface(
|
||||
struct wlr_wl_shell_surface *surface, double lx, double ly,
|
||||
float rotation, bool is_child, surface_iterator_func_t iterator,
|
||||
|
@ -117,6 +146,12 @@ static void view_for_each_surface(struct roots_view *view,
|
|||
xdg_surface_v6_for_each_surface(view->xdg_surface_v6, view->x, view->y,
|
||||
view->rotation, iterator, user_data);
|
||||
break;
|
||||
case ROOTS_XDG_SHELL_VIEW:
|
||||
surface_for_each_surface(view->wlr_surface, view->x, view->y,
|
||||
view->rotation, iterator, user_data);
|
||||
xdg_surface_for_each_surface(view->xdg_surface, view->x, view->y,
|
||||
view->rotation, iterator, user_data);
|
||||
break;
|
||||
case ROOTS_WL_SHELL_VIEW:
|
||||
wl_shell_surface_for_each_surface(view->wl_shell_surface, view->x,
|
||||
view->y, view->rotation, false, iterator, user_data);
|
||||
|
@ -337,6 +372,8 @@ static bool has_standalone_surface(struct roots_view *view) {
|
|||
switch (view->type) {
|
||||
case ROOTS_XDG_SHELL_V6_VIEW:
|
||||
return wl_list_empty(&view->xdg_surface_v6->popups);
|
||||
case ROOTS_XDG_SHELL_VIEW:
|
||||
return wl_list_empty(&view->xdg_surface->popups);
|
||||
case ROOTS_WL_SHELL_VIEW:
|
||||
return wl_list_empty(&view->wl_shell_surface->popups);
|
||||
#ifdef WLR_HAS_XWAYLAND
|
||||
|
|
|
@ -0,0 +1,363 @@
|
|||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "rootston/desktop.h"
|
||||
#include "rootston/input.h"
|
||||
#include "rootston/server.h"
|
||||
|
||||
static void popup_destroy(struct roots_view_child *child) {
|
||||
assert(child->destroy == popup_destroy);
|
||||
struct roots_xdg_popup *popup = (struct roots_xdg_popup *)child;
|
||||
if (popup == NULL) {
|
||||
return;
|
||||
}
|
||||
wl_list_remove(&popup->destroy.link);
|
||||
wl_list_remove(&popup->new_popup.link);
|
||||
view_child_finish(&popup->view_child);
|
||||
free(popup);
|
||||
}
|
||||
|
||||
static void popup_handle_destroy(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_popup *popup =
|
||||
wl_container_of(listener, popup, destroy);
|
||||
popup_destroy((struct roots_view_child *)popup);
|
||||
}
|
||||
|
||||
static struct roots_xdg_popup *popup_create(struct roots_view *view,
|
||||
struct wlr_xdg_popup *wlr_popup);
|
||||
|
||||
static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_popup *popup =
|
||||
wl_container_of(listener, popup, new_popup);
|
||||
struct wlr_xdg_popup *wlr_popup = data;
|
||||
popup_create(popup->view_child.view, wlr_popup);
|
||||
}
|
||||
|
||||
static struct roots_xdg_popup *popup_create(struct roots_view *view,
|
||||
struct wlr_xdg_popup *wlr_popup) {
|
||||
struct roots_xdg_popup *popup =
|
||||
calloc(1, sizeof(struct roots_xdg_popup));
|
||||
if (popup == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
popup->wlr_popup = wlr_popup;
|
||||
popup->view_child.destroy = popup_destroy;
|
||||
view_child_init(&popup->view_child, view, wlr_popup->base->surface);
|
||||
popup->destroy.notify = popup_handle_destroy;
|
||||
wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy);
|
||||
popup->new_popup.notify = popup_handle_new_popup;
|
||||
wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup);
|
||||
return popup;
|
||||
}
|
||||
|
||||
|
||||
static void get_size(const struct roots_view *view, struct wlr_box *box) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
|
||||
if (surface->geometry->width > 0 && surface->geometry->height > 0) {
|
||||
box->width = surface->geometry->width;
|
||||
box->height = surface->geometry->height;
|
||||
} else {
|
||||
box->width = view->wlr_surface->current->width;
|
||||
box->height = view->wlr_surface->current->height;
|
||||
}
|
||||
}
|
||||
|
||||
static void activate(struct roots_view *view, bool active) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
||||
wlr_xdg_toplevel_set_activated(surface, active);
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_size_constraints(struct wlr_xdg_surface *surface,
|
||||
uint32_t width, uint32_t height, uint32_t *dest_width,
|
||||
uint32_t *dest_height) {
|
||||
*dest_width = width;
|
||||
*dest_height = height;
|
||||
|
||||
struct wlr_xdg_toplevel_state *state = &surface->toplevel_state->current;
|
||||
if (width < state->min_width) {
|
||||
*dest_width = state->min_width;
|
||||
} else if (state->max_width > 0 &&
|
||||
width > state->max_width) {
|
||||
*dest_width = state->max_width;
|
||||
}
|
||||
if (height < state->min_height) {
|
||||
*dest_height = state->min_height;
|
||||
} else if (state->max_height > 0 &&
|
||||
height > state->max_height) {
|
||||
*dest_height = state->max_height;
|
||||
}
|
||||
}
|
||||
|
||||
static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t constrained_width, constrained_height;
|
||||
apply_size_constraints(surface, width, height, &constrained_width,
|
||||
&constrained_height);
|
||||
|
||||
wlr_xdg_toplevel_set_size(surface, constrained_width,
|
||||
constrained_height);
|
||||
}
|
||||
|
||||
static void move_resize(struct roots_view *view, double x, double y,
|
||||
uint32_t width, uint32_t height) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
||||
struct roots_xdg_surface *roots_surface = view->roots_xdg_surface;
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool update_x = x != view->x;
|
||||
bool update_y = y != view->y;
|
||||
|
||||
uint32_t constrained_width, constrained_height;
|
||||
apply_size_constraints(surface, width, height, &constrained_width,
|
||||
&constrained_height);
|
||||
|
||||
if (update_x) {
|
||||
x = x + width - constrained_width;
|
||||
}
|
||||
if (update_y) {
|
||||
y = y + height - constrained_height;
|
||||
}
|
||||
|
||||
view->pending_move_resize.update_x = update_x;
|
||||
view->pending_move_resize.update_y = update_y;
|
||||
view->pending_move_resize.x = x;
|
||||
view->pending_move_resize.y = y;
|
||||
view->pending_move_resize.width = constrained_width;
|
||||
view->pending_move_resize.height = constrained_height;
|
||||
|
||||
uint32_t serial = wlr_xdg_toplevel_set_size(surface, constrained_width,
|
||||
constrained_height);
|
||||
if (serial > 0) {
|
||||
roots_surface->pending_move_resize_configure_serial = serial;
|
||||
} else if (roots_surface->pending_move_resize_configure_serial == 0) {
|
||||
view_update_position(view, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
static void maximize(struct roots_view *view, bool maximized) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_xdg_toplevel_set_maximized(surface, maximized);
|
||||
}
|
||||
|
||||
static void set_fullscreen(struct roots_view *view, bool fullscreen) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_xdg_toplevel_set_fullscreen(surface, fullscreen);
|
||||
}
|
||||
|
||||
static void close(struct roots_view *view) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
||||
wlr_xdg_toplevel_send_close(surface);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_request_move(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, request_move);
|
||||
struct roots_view *view = roots_xdg_surface->view;
|
||||
struct roots_input *input = view->desktop->server->input;
|
||||
struct wlr_xdg_toplevel_move_event *e = data;
|
||||
struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat);
|
||||
// TODO verify event serial
|
||||
if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
|
||||
return;
|
||||
}
|
||||
roots_seat_begin_move(seat, view);
|
||||
}
|
||||
|
||||
static void handle_request_resize(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, request_resize);
|
||||
struct roots_view *view = roots_xdg_surface->view;
|
||||
struct roots_input *input = view->desktop->server->input;
|
||||
struct wlr_xdg_toplevel_resize_event *e = data;
|
||||
// TODO verify event serial
|
||||
struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat);
|
||||
assert(seat);
|
||||
if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
|
||||
return;
|
||||
}
|
||||
roots_seat_begin_resize(seat, view, e->edges);
|
||||
}
|
||||
|
||||
static void handle_request_maximize(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, request_maximize);
|
||||
struct roots_view *view = roots_xdg_surface->view;
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
|
||||
if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
view_maximize(view, surface->toplevel_state->next.maximized);
|
||||
}
|
||||
|
||||
static void handle_request_fullscreen(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct roots_xdg_surface *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, request_fullscreen);
|
||||
struct roots_view *view = roots_xdg_surface->view;
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
struct wlr_xdg_toplevel_set_fullscreen_event *e = data;
|
||||
|
||||
if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
view_set_fullscreen(view, e->fullscreen, e->output);
|
||||
}
|
||||
|
||||
static void handle_surface_commit(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface *roots_surface =
|
||||
wl_container_of(listener, roots_surface, surface_commit);
|
||||
struct roots_view *view = roots_surface->view;
|
||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||
|
||||
view_apply_damage(view);
|
||||
|
||||
struct wlr_box size;
|
||||
get_size(view, &size);
|
||||
view_update_size(view, size.width, size.height);
|
||||
|
||||
uint32_t pending_serial =
|
||||
roots_surface->pending_move_resize_configure_serial;
|
||||
if (pending_serial > 0 && pending_serial >= surface->configure_serial) {
|
||||
double x = view->x;
|
||||
double y = view->y;
|
||||
if (view->pending_move_resize.update_x) {
|
||||
x = view->pending_move_resize.x + view->pending_move_resize.width -
|
||||
size.width;
|
||||
}
|
||||
if (view->pending_move_resize.update_y) {
|
||||
y = view->pending_move_resize.y + view->pending_move_resize.height -
|
||||
size.height;
|
||||
}
|
||||
view_update_position(view, x, y);
|
||||
|
||||
if (pending_serial == surface->configure_serial) {
|
||||
roots_surface->pending_move_resize_configure_serial = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_new_popup(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, new_popup);
|
||||
struct wlr_xdg_popup *wlr_popup = data;
|
||||
popup_create(roots_xdg_surface->view, wlr_popup);
|
||||
}
|
||||
|
||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, destroy);
|
||||
wl_list_remove(&roots_xdg_surface->surface_commit.link);
|
||||
wl_list_remove(&roots_xdg_surface->destroy.link);
|
||||
wl_list_remove(&roots_xdg_surface->new_popup.link);
|
||||
wl_list_remove(&roots_xdg_surface->request_move.link);
|
||||
wl_list_remove(&roots_xdg_surface->request_resize.link);
|
||||
wl_list_remove(&roots_xdg_surface->request_maximize.link);
|
||||
wl_list_remove(&roots_xdg_surface->request_fullscreen.link);
|
||||
wl_list_remove(&roots_xdg_surface->view->link);
|
||||
view_finish(roots_xdg_surface->view);
|
||||
free(roots_xdg_surface->view);
|
||||
free(roots_xdg_surface);
|
||||
}
|
||||
|
||||
void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
|
||||
struct wlr_xdg_surface *surface = data;
|
||||
assert(surface->role != WLR_XDG_SURFACE_ROLE_NONE);
|
||||
|
||||
if (surface->role == WLR_XDG_SURFACE_ROLE_POPUP) {
|
||||
wlr_log(L_DEBUG, "new xdg popup");
|
||||
return;
|
||||
}
|
||||
|
||||
struct roots_desktop *desktop =
|
||||
wl_container_of(listener, desktop, xdg_shell_surface);
|
||||
|
||||
wlr_log(L_DEBUG, "new xdg toplevel: title=%s, app_id=%s",
|
||||
surface->title, surface->app_id);
|
||||
wlr_xdg_surface_ping(surface);
|
||||
|
||||
struct roots_xdg_surface *roots_surface =
|
||||
calloc(1, sizeof(struct roots_xdg_surface));
|
||||
if (!roots_surface) {
|
||||
return;
|
||||
}
|
||||
roots_surface->surface_commit.notify = handle_surface_commit;
|
||||
wl_signal_add(&surface->surface->events.commit,
|
||||
&roots_surface->surface_commit);
|
||||
roots_surface->destroy.notify = handle_destroy;
|
||||
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
|
||||
roots_surface->request_move.notify = handle_request_move;
|
||||
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
|
||||
roots_surface->request_resize.notify = handle_request_resize;
|
||||
wl_signal_add(&surface->events.request_resize,
|
||||
&roots_surface->request_resize);
|
||||
roots_surface->request_maximize.notify = handle_request_maximize;
|
||||
wl_signal_add(&surface->events.request_maximize,
|
||||
&roots_surface->request_maximize);
|
||||
roots_surface->request_fullscreen.notify = handle_request_fullscreen;
|
||||
wl_signal_add(&surface->events.request_fullscreen,
|
||||
&roots_surface->request_fullscreen);
|
||||
roots_surface->new_popup.notify = handle_new_popup;
|
||||
wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup);
|
||||
|
||||
struct roots_view *view = calloc(1, sizeof(struct roots_view));
|
||||
if (!view) {
|
||||
free(roots_surface);
|
||||
return;
|
||||
}
|
||||
view->type = ROOTS_XDG_SHELL_VIEW;
|
||||
|
||||
view->xdg_surface = surface;
|
||||
view->roots_xdg_surface = roots_surface;
|
||||
view->wlr_surface = surface->surface;
|
||||
view->activate = activate;
|
||||
view->resize = resize;
|
||||
view->move_resize = move_resize;
|
||||
view->maximize = maximize;
|
||||
view->set_fullscreen = set_fullscreen;
|
||||
view->close = close;
|
||||
roots_surface->view = view;
|
||||
|
||||
struct wlr_box box;
|
||||
get_size(view, &box);
|
||||
view->width = box.width;
|
||||
view->height = box.height;
|
||||
|
||||
view_init(view, desktop);
|
||||
wl_list_insert(&desktop->views, &view->link);
|
||||
|
||||
view_setup(view);
|
||||
}
|
|
@ -26,6 +26,7 @@ lib_wlr_types = static_library(
|
|||
'wlr_wl_shell.c',
|
||||
'wlr_xcursor_manager.c',
|
||||
'wlr_xdg_shell_v6.c',
|
||||
'wlr_xdg_shell.c',
|
||||
),
|
||||
include_directories: wlr_inc,
|
||||
dependencies: [wayland_server, pixman, wlr_protos],
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue