Merge branch 'master' into feature/xwm-selection

This commit is contained in:
Tony Crisci 2017-12-08 09:22:44 -05:00
commit 35188834db
48 changed files with 1130 additions and 591 deletions

View File

@ -634,8 +634,10 @@ static bool wlr_drm_connector_move_cursor(struct wlr_output *output,
struct wlr_box transformed_box; struct wlr_box transformed_box;
wlr_output_transform_apply_to_box(transform, &box, &transformed_box); wlr_output_transform_apply_to_box(transform, &box, &transformed_box);
if (plane != NULL) {
transformed_box.x -= plane->cursor_hotspot_x; transformed_box.x -= plane->cursor_hotspot_x;
transformed_box.y -= plane->cursor_hotspot_y; transformed_box.y -= plane->cursor_hotspot_y;
}
return drm->iface->crtc_move_cursor(drm, conn->crtc, transformed_box.x, return drm->iface->crtc_move_cursor(drm, conn->crtc, transformed_box.x,
transformed_box.y); transformed_box.y);

View File

@ -14,7 +14,7 @@
#include <wlr/render/gles2.h> #include <wlr/render/gles2.h>
#include <wlr/render.h> #include <wlr/render.h>
#include "backend/drm/drm.h" #include "backend/drm/drm.h"
#include "render/glapi.h" #include "glapi.h"
bool wlr_drm_renderer_init(struct wlr_drm_backend *drm, bool wlr_drm_renderer_init(struct wlr_drm_backend *drm,
struct wlr_drm_renderer *renderer) { struct wlr_drm_renderer *renderer) {

View File

@ -93,6 +93,12 @@ void parse_edid(struct wlr_output *restrict output, size_t len, const uint8_t *d
uint16_t id = (data[8] << 8) | data[9]; uint16_t id = (data[8] << 8) | data[9];
snprintf(output->make, sizeof(output->make), "%s", get_manufacturer(id)); snprintf(output->make, sizeof(output->make), "%s", get_manufacturer(id));
uint16_t model = data[10] | (data[11] << 8);
snprintf(output->model, sizeof(output->model), "0x%04X", model);
uint32_t serial = data[12] | (data[13] << 8) | (data[14] << 8) | (data[15] << 8);
snprintf(output->serial, sizeof(output->serial), "0x%08X", serial);
output->phys_width = ((data[68] & 0xf0) << 4) | data[66]; output->phys_width = ((data[68] & 0xf0) << 4) | data[66];
output->phys_height = ((data[68] & 0x0f) << 8) | data[67]; output->phys_height = ((data[68] & 0x0f) << 8) | data[67];

View File

@ -21,7 +21,6 @@ backend_files = files(
'wayland/output.c', 'wayland/output.c',
'wayland/registry.c', 'wayland/registry.c',
'wayland/wl_seat.c', 'wayland/wl_seat.c',
'wayland/os-compatibility.c',
'x11/backend.c', 'x11/backend.c',
) )

View File

@ -148,8 +148,8 @@ static bool setup_tty(struct direct_session *session, struct wl_display *display
struct vt_mode mode = { struct vt_mode mode = {
.mode = VT_PROCESS, .mode = VT_PROCESS,
.relsig = SIGUSR1, .relsig = SIGUSR2,
.acqsig = SIGUSR1, .acqsig = SIGUSR2,
.frsig = SIGIO, // has to be set .frsig = SIGIO, // has to be set
}; };
@ -159,7 +159,7 @@ static bool setup_tty(struct direct_session *session, struct wl_display *display
} }
struct wl_event_loop *loop = wl_display_get_event_loop(display); struct wl_event_loop *loop = wl_display_get_event_loop(display);
session->vt_source = wl_event_loop_add_signal(loop, SIGUSR1, session->vt_source = wl_event_loop_add_signal(loop, SIGUSR2,
vt_handler, session); vt_handler, session);
if (!session->vt_source) { if (!session->vt_source) {
goto error; goto error;

View File

@ -184,8 +184,8 @@ static bool setup_tty(struct direct_session *session, struct wl_display *display
struct vt_mode mode = { struct vt_mode mode = {
.mode = VT_PROCESS, .mode = VT_PROCESS,
.relsig = SIGUSR1, .relsig = SIGUSR2,
.acqsig = SIGUSR1, .acqsig = SIGUSR2,
}; };
if (ioctl(fd, VT_SETMODE, &mode) < 0) { if (ioctl(fd, VT_SETMODE, &mode) < 0) {
@ -194,7 +194,7 @@ static bool setup_tty(struct direct_session *session, struct wl_display *display
} }
struct wl_event_loop *loop = wl_display_get_event_loop(display); struct wl_event_loop *loop = wl_display_get_event_loop(display);
session->vt_source = wl_event_loop_add_signal(loop, SIGUSR1, session->vt_source = wl_event_loop_add_signal(loop, SIGUSR2,
vt_handler, session); vt_handler, session);
if (!session->vt_source) { if (!session->vt_source) {
goto error; goto error;

View File

@ -347,12 +347,6 @@ static struct wlr_session *logind_session_create(struct wl_display *disp) {
goto error; goto error;
} }
ret = sd_session_get_vt(session->id, &session->base.vtnr);
if (ret < 0) {
wlr_log(L_ERROR, "Session not running in virtual terminal");
goto error;
}
char *seat; char *seat;
ret = sd_session_get_seat(session->id, &seat); ret = sd_session_get_seat(session->id, &seat);
if (ret < 0) { if (ret < 0) {
@ -360,6 +354,14 @@ static struct wlr_session *logind_session_create(struct wl_display *disp) {
goto error; goto error;
} }
snprintf(session->base.seat, sizeof(session->base.seat), "%s", seat); snprintf(session->base.seat, sizeof(session->base.seat), "%s", seat);
if (strcmp(seat, "seat0") == 0) {
ret = sd_session_get_vt(session->id, &session->base.vtnr);
if (ret < 0) {
wlr_log(L_ERROR, "Session not running in virtual terminal");
goto error;
}
}
free(seat); free(seat);
ret = sd_bus_default_system(&session->bus); ret = sd_bus_default_system(&session->bus);

View File

@ -29,5 +29,6 @@ executable(
executable( executable(
'screenshot', 'screenshot',
'screenshot.c', 'screenshot.c',
dependencies: [wayland_client, wlr_protos], dependencies: [wayland_client, wlr_protos, wlroots],
link_with: lib_shared,
) )

View File

@ -35,7 +35,7 @@
#include <limits.h> #include <limits.h>
#include <sys/param.h> #include <sys/param.h>
#include <screenshooter-client-protocol.h> #include <screenshooter-client-protocol.h>
#include "../backend/wayland/os-compatibility.c" #include "util/os-compatibility.h"
static struct wl_shm *shm = NULL; static struct wl_shm *shm = NULL;
static struct orbital_screenshooter *screenshooter = NULL; static struct orbital_screenshooter *screenshooter = NULL;

View File

@ -7,15 +7,16 @@
# to fail if it can't load the function. You'll need to check if that function # to fail if it can't load the function. You'll need to check if that function
# is NULL before using it. # is NULL before using it.
if [ $# -ne 2 ]; then if [ $# -ne 3 ]; then
exit 1 exit 1
fi fi
SPEC=$1 SPEC=$1
OUT=$2 OUT_C=$2
OUT_H=$3
BASE=$(basename "$SPEC" .txt) BASE=$(basename "$SPEC" .txt)
INCLUDE_GUARD=$(printf %s "$SPEC" | tr -c [:alnum:] _ | tr [:lower:] [:upper:]) INCLUDE_GUARD=$(printf %s "$OUT_H" | tr -c [:alnum:] _ | tr [:lower:] [:upper:])
DECL="" DECL=""
DEFN="" DEFN=""
@ -57,10 +58,7 @@ while read -r COMMAND; do
fi fi
done < $SPEC done < $SPEC
cat > $OUT_H << EOF
case $OUT in
*.h)
cat > $OUT << EOF
#ifndef $INCLUDE_GUARD #ifndef $INCLUDE_GUARD
#define $INCLUDE_GUARD #define $INCLUDE_GUARD
@ -77,11 +75,10 @@ case $OUT in
#endif #endif
EOF EOF
;;
*.c) cat > $OUT_C << EOF
cat > $OUT << EOF
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "$BASE.h" #include "$OUT_H"
$DEFN $DEFN
bool load_$BASE(void) { bool load_$BASE(void) {
@ -95,8 +92,3 @@ EOF
return true; return true;
} }
EOF EOF
;;
*)
exit 1
;;
esac

View File

@ -10,13 +10,6 @@ enum roots_cursor_mode {
ROOTS_CURSOR_ROTATE = 3, ROOTS_CURSOR_ROTATE = 3,
}; };
enum roots_cursor_resize_edge {
ROOTS_CURSOR_RESIZE_EDGE_TOP = 1,
ROOTS_CURSOR_RESIZE_EDGE_BOTTOM = 2,
ROOTS_CURSOR_RESIZE_EDGE_LEFT = 4,
ROOTS_CURSOR_RESIZE_EDGE_RIGHT = 8,
};
struct roots_input_event { struct roots_input_event {
uint32_t serial; uint32_t serial;
struct wlr_cursor *cursor; struct wlr_cursor *cursor;

View File

@ -19,13 +19,14 @@ struct roots_output {
struct wlr_output *wlr_output; struct wlr_output *wlr_output;
struct wl_listener frame; struct wl_listener frame;
struct timespec last_frame; struct timespec last_frame;
struct wl_list link; struct wl_list link; // roots_desktop:outputs
struct roots_view *fullscreen_view;
}; };
struct roots_desktop { struct roots_desktop {
struct wl_list views; // roots_view::link struct wl_list views; // roots_view::link
struct wl_list outputs; struct wl_list outputs; // roots_output::link
struct timespec last_frame; struct timespec last_frame;
struct roots_server *server; struct roots_server *server;
@ -59,11 +60,13 @@ struct roots_server;
struct roots_desktop *desktop_create(struct roots_server *server, struct roots_desktop *desktop_create(struct roots_server *server,
struct roots_config *config); struct roots_config *config);
void desktop_destroy(struct roots_desktop *desktop); void desktop_destroy(struct roots_desktop *desktop);
struct roots_output *desktop_output_from_wlr_output(
struct roots_desktop *desktop, struct wlr_output *output);
struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
double ly, struct wlr_surface **surface, double *sx, double *sy);
void view_init(struct roots_view *view, struct roots_desktop *desktop); void view_init(struct roots_view *view, struct roots_desktop *desktop);
void view_destroy(struct roots_view *view); void view_destroy(struct roots_view *view);
struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy);
void view_activate(struct roots_view *view, bool activate); void view_activate(struct roots_view *view, bool activate);
void output_add_notify(struct wl_listener *listener, void *data); void output_add_notify(struct wl_listener *listener, void *data);

View File

@ -12,7 +12,8 @@ struct roots_wl_shell_surface {
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
struct wl_listener request_set_maximized; struct wl_listener request_maximize;
struct wl_listener request_fullscreen;
struct wl_listener set_state; struct wl_listener set_state;
struct wl_listener surface_commit; struct wl_listener surface_commit;
@ -26,6 +27,9 @@ struct roots_xdg_surface_v6 {
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
struct wl_listener request_maximize; struct wl_listener request_maximize;
struct wl_listener request_fullscreen;
uint32_t pending_move_resize_configure_serial;
}; };
struct roots_xwayland_surface { struct roots_xwayland_surface {
@ -36,8 +40,11 @@ struct roots_xwayland_surface {
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
struct wl_listener request_maximize; struct wl_listener request_maximize;
struct wl_listener request_fullscreen;
struct wl_listener map_notify; struct wl_listener map_notify;
struct wl_listener unmap_notify; struct wl_listener unmap_notify;
struct wl_listener surface_commit;
}; };
enum roots_view_type { enum roots_view_type {
@ -54,12 +61,19 @@ struct roots_view {
float rotation; float rotation;
bool maximized; bool maximized;
struct roots_output *fullscreen_output;
struct { struct {
double x, y; double x, y;
uint32_t width, height; uint32_t width, height;
float rotation; float rotation;
} saved; } saved;
struct {
bool update_x, update_y;
double x, y;
uint32_t width, height;
} pending_move_resize;
// TODO: Something for roots-enforced width/height // TODO: Something for roots-enforced width/height
enum roots_view_type type; enum roots_view_type type;
union { union {
@ -93,6 +107,7 @@ struct roots_view {
void (*move_resize)(struct roots_view *view, double x, double y, void (*move_resize)(struct roots_view *view, double x, double y,
uint32_t width, uint32_t height); uint32_t width, uint32_t height);
void (*maximize)(struct roots_view *view, bool maximized); void (*maximize)(struct roots_view *view, bool maximized);
void (*set_fullscreen)(struct roots_view *view, bool fullscreen);
void (*close)(struct roots_view *view); void (*close)(struct roots_view *view);
}; };
@ -103,6 +118,8 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
void view_move_resize(struct roots_view *view, double x, double y, void view_move_resize(struct roots_view *view, double x, double y,
uint32_t width, uint32_t height); uint32_t width, uint32_t height);
void view_maximize(struct roots_view *view, bool maximized); void view_maximize(struct roots_view *view, bool maximized);
void view_set_fullscreen(struct roots_view *view, bool fullscreen,
struct wlr_output *output);
void view_close(struct roots_view *view); void view_close(struct roots_view *view);
bool view_center(struct roots_view *view); bool view_center(struct roots_view *view);
void view_setup(struct roots_view *view); void view_setup(struct roots_view *view);

View File

@ -3,12 +3,10 @@
#include <stdint.h> #include <stdint.h>
#define ROOTS_XCURSOR_SIZE 16 #define ROOTS_XCURSOR_SIZE 24
#define ROOTS_XCURSOR_DEFAULT "left_ptr" #define ROOTS_XCURSOR_DEFAULT "left_ptr"
#define ROOTS_XCURSOR_MOVE "grabbing" #define ROOTS_XCURSOR_MOVE "grabbing"
#define ROOTS_XCURSOR_ROTATE "grabbing" #define ROOTS_XCURSOR_ROTATE "grabbing"
const char *roots_xcursor_get_resize_name(uint32_t edges);
#endif #endif

View File

@ -0,0 +1,12 @@
#ifndef _WLR_UTIL_OS_COMPATIBILITY_H
#define _WLR_UTIL_OS_COMPATIBILITY_H
int os_fd_set_cloexec(int fd);
int set_cloexec_or_close(int fd);
int create_tmpfile_cloexec(char *tmpname);
int os_create_anonymous_file(off_t size);
#endif

View File

@ -16,6 +16,7 @@ struct wlr_output_cursor {
struct wlr_output *output; struct wlr_output *output;
double x, y; double x, y;
bool enabled; bool enabled;
bool visible;
uint32_t width, height; uint32_t width, height;
int32_t hotspot_x, hotspot_y; int32_t hotspot_x, hotspot_y;
struct wl_list link; struct wl_list link;
@ -64,6 +65,10 @@ struct wlr_output {
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;
struct wlr_surface *fullscreen_surface;
struct wl_listener fullscreen_surface_commit;
struct wl_listener fullscreen_surface_destroy;
struct wl_list cursors; // wlr_output_cursor::link struct wl_list cursors; // wlr_output_cursor::link
struct wlr_output_cursor *hardware_cursor; struct wlr_output_cursor *hardware_cursor;
@ -81,6 +86,7 @@ bool wlr_output_set_mode(struct wlr_output *output,
void wlr_output_transform(struct wlr_output *output, void wlr_output_transform(struct wlr_output *output,
enum wl_output_transform transform); enum wl_output_transform transform);
void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly); void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly);
void wlr_output_set_scale(struct wlr_output *output, uint32_t scale);
void wlr_output_destroy(struct wlr_output *output); void wlr_output_destroy(struct wlr_output *output);
void wlr_output_effective_resolution(struct wlr_output *output, void wlr_output_effective_resolution(struct wlr_output *output,
int *width, int *height); int *width, int *height);
@ -89,8 +95,13 @@ void wlr_output_swap_buffers(struct wlr_output *output);
void wlr_output_set_gamma(struct wlr_output *output, void wlr_output_set_gamma(struct wlr_output *output,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
uint32_t wlr_output_get_gamma_size(struct wlr_output *output); uint32_t wlr_output_get_gamma_size(struct wlr_output *output);
void wlr_output_set_fullscreen_surface(struct wlr_output *output,
struct wlr_surface *surface);
struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output); struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output);
/**
* Sets the cursor image. The image must be already scaled for the output.
*/
bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height,
int32_t hotspot_x, int32_t hotspot_y); int32_t hotspot_x, int32_t hotspot_y);

View File

@ -3,12 +3,35 @@
#include <wayland-server.h> #include <wayland-server.h>
/**
* Possible values to use in request_mode and the event mode. Same as
* org_kde_kwin_server_decoration_manager_mode.
*/
enum wlr_server_decoration_manager_mode {
/**
* Undecorated: The surface is not decorated at all, neither server nor
* client-side. An example is a popup surface which should not be
* decorated.
*/
WLR_SERVER_DECORATION_MANAGER_MODE_NONE = 0,
/**
* Client-side decoration: The decoration is part of the surface and the
* client.
*/
WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT = 1,
/**
* Server-side decoration: The server embeds the surface into a decoration
* frame.
*/
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER = 2,
};
struct wlr_server_decoration_manager { struct wlr_server_decoration_manager {
struct wl_global *wl_global; struct wl_global *wl_global;
struct wl_list wl_resources; struct wl_list wl_resources;
struct wl_list decorations; // wlr_server_decoration::link struct wl_list decorations; // wlr_server_decoration::link
uint32_t default_mode; // enum org_kde_kwin_server_decoration_manager_mode uint32_t default_mode; // enum wlr_server_decoration_manager_mode
struct { struct {
struct wl_signal new_decoration; struct wl_signal new_decoration;
@ -22,7 +45,7 @@ struct wlr_server_decoration {
struct wlr_surface *surface; struct wlr_surface *surface;
struct wl_list link; struct wl_list link;
uint32_t mode; // enum org_kde_kwin_server_decoration_manager_mode uint32_t mode; // enum wlr_server_decoration_manager_mode
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;

View File

@ -1,9 +1,10 @@
#ifndef WLR_TYPES_WLR_SURFACE_H #ifndef WLR_TYPES_WLR_SURFACE_H
#define WLR_TYPES_WLR_SURFACE_H #define WLR_TYPES_WLR_SURFACE_H
#include <wayland-server.h>
#include <pixman.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <time.h>
#include <pixman.h>
#include <wayland-server.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
struct wlr_frame_callback { struct wlr_frame_callback {
@ -142,4 +143,7 @@ void wlr_surface_send_enter(struct wlr_surface *surface,
void wlr_surface_send_leave(struct wlr_surface *surface, void wlr_surface_send_leave(struct wlr_surface *surface,
struct wlr_output *output); struct wlr_output *output);
void wlr_surface_send_frame_done(struct wlr_surface *surface,
const struct timespec *when);
#endif #endif

View File

@ -77,12 +77,13 @@ struct wlr_wl_shell_surface {
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
struct wl_signal commit;
struct wl_signal ping_timeout; struct wl_signal ping_timeout;
struct wl_signal request_move; struct wl_signal request_move;
struct wl_signal request_resize; struct wl_signal request_resize;
struct wl_signal request_set_fullscreen; struct wl_signal request_fullscreen;
struct wl_signal request_set_maximized; struct wl_signal request_maximize;
struct wl_signal set_state; struct wl_signal set_state;
struct wl_signal set_title; struct wl_signal set_title;
@ -93,14 +94,12 @@ struct wlr_wl_shell_surface {
}; };
struct wlr_wl_shell_surface_move_event { struct wlr_wl_shell_surface_move_event {
struct wl_client *client;
struct wlr_wl_shell_surface *surface; struct wlr_wl_shell_surface *surface;
struct wlr_seat_client *seat; struct wlr_seat_client *seat;
uint32_t serial; uint32_t serial;
}; };
struct wlr_wl_shell_surface_resize_event { struct wlr_wl_shell_surface_resize_event {
struct wl_client *client;
struct wlr_wl_shell_surface *surface; struct wlr_wl_shell_surface *surface;
struct wlr_seat_client *seat; struct wlr_seat_client *seat;
uint32_t serial; uint32_t serial;
@ -108,15 +107,13 @@ struct wlr_wl_shell_surface_resize_event {
}; };
struct wlr_wl_shell_surface_set_fullscreen_event { struct wlr_wl_shell_surface_set_fullscreen_event {
struct wl_client *client;
struct wlr_wl_shell_surface *surface; struct wlr_wl_shell_surface *surface;
enum wl_shell_surface_fullscreen_method method; enum wl_shell_surface_fullscreen_method method;
uint32_t framerate; uint32_t framerate;
struct wlr_output *output; struct wlr_output *output;
}; };
struct wlr_wl_shell_surface_set_maximized_event { struct wlr_wl_shell_surface_maximize_event {
struct wl_client *client;
struct wlr_wl_shell_surface *surface; struct wlr_wl_shell_surface *surface;
struct wlr_output *output; struct wlr_output *output;
}; };

View File

@ -107,7 +107,9 @@ struct wlr_xdg_surface_v6 {
bool configured; bool configured;
bool added; bool added;
uint32_t configure_serial;
struct wl_event_source *configure_idle; struct wl_event_source *configure_idle;
uint32_t configure_next_serial;
struct wl_list configure_list; struct wl_list configure_list;
char *title; char *title;
@ -123,7 +125,6 @@ struct wlr_xdg_surface_v6 {
struct { struct {
struct wl_signal commit; struct wl_signal commit;
struct wl_signal destroy; struct wl_signal destroy;
struct wl_signal ack_configure;
struct wl_signal ping_timeout; struct wl_signal ping_timeout;
struct wl_signal request_maximize; struct wl_signal request_maximize;
@ -138,27 +139,29 @@ struct wlr_xdg_surface_v6 {
}; };
struct wlr_xdg_toplevel_v6_move_event { struct wlr_xdg_toplevel_v6_move_event {
struct wl_client *client;
struct wlr_xdg_surface_v6 *surface; struct wlr_xdg_surface_v6 *surface;
struct wlr_seat_client *seat; struct wlr_seat_client *seat;
uint32_t serial; uint32_t serial;
}; };
struct wlr_xdg_toplevel_v6_resize_event { struct wlr_xdg_toplevel_v6_resize_event {
struct wl_client *client;
struct wlr_xdg_surface_v6 *surface; struct wlr_xdg_surface_v6 *surface;
struct wlr_seat_client *seat; struct wlr_seat_client *seat;
uint32_t serial; uint32_t serial;
uint32_t edges; uint32_t edges;
}; };
struct wlr_xdg_toplevel_v6_set_fullscreen_event {
struct wlr_xdg_surface_v6 *surface;
bool fullscreen;
struct wlr_output *output;
};
struct wlr_xdg_toplevel_v6_show_window_menu_event { struct wlr_xdg_toplevel_v6_show_window_menu_event {
struct wl_client *client;
struct wlr_xdg_surface_v6 *surface; struct wlr_xdg_surface_v6 *surface;
struct wlr_seat_client *seat; struct wlr_seat_client *seat;
uint32_t serial; uint32_t serial;
uint32_t x; uint32_t x, y;
uint32_t y;
}; };
struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display); struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display);
@ -171,37 +174,38 @@ void wlr_xdg_shell_v6_destroy(struct wlr_xdg_shell_v6 *xdg_shell);
void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface); void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface);
/** /**
* Request that this toplevel surface be the given size. * Request that this toplevel surface be the given size. Returns the associated
* configure serial.
*/ */
void wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface,
uint32_t width, uint32_t height); uint32_t width, uint32_t height);
/** /**
* Request that this toplevel surface show itself in an activated or deactivated * Request that this toplevel surface show itself in an activated or deactivated
* state. * state. Returns the associated configure serial.
*/ */
void wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface,
bool activated); bool activated);
/** /**
* Request that this toplevel surface consider itself maximized or not * Request that this toplevel surface consider itself maximized or not
* maximized. * maximized. Returns the associated configure serial.
*/ */
void wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface,
bool maximized); bool maximized);
/** /**
* Request that this toplevel surface consider itself fullscreen or not * Request that this toplevel surface consider itself fullscreen or not
* fullscreen. * fullscreen. Returns the associated configure serial.
*/ */
void wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface,
bool fullscreen); bool fullscreen);
/** /**
* Request that this toplevel surface consider itself to be resizing or not * Request that this toplevel surface consider itself to be resizing or not
* resizing. * resizing. Returns the associated configure serial.
*/ */
void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface,
bool resizing); bool resizing);
/** /**
@ -223,4 +227,5 @@ void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface,
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at(
struct wlr_xdg_surface_v6 *surface, double sx, double sy, struct wlr_xdg_surface_v6 *surface, double sx, double sy,
double *popup_sx, double *popup_sy); double *popup_sx, double *popup_sy);
#endif #endif

12
include/wlr/util/edges.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef WLR_UTIL_EDGES_H
#define WLR_UTIL_EDGES_H
enum wlr_edges {
WLR_EDGE_NONE = 0,
WLR_EDGE_TOP = 1,
WLR_EDGE_BOTTOM = 2,
WLR_EDGE_LEFT = 4,
WLR_EDGE_RIGHT = 8,
};
#endif

View File

@ -32,6 +32,7 @@
#define WLR_XCURSOR_H #define WLR_XCURSOR_H
#include <stdint.h> #include <stdint.h>
#include <wlr/util/edges.h>
struct wlr_xcursor_image { struct wlr_xcursor_image {
uint32_t width; /* actual width */ uint32_t width; /* actual width */
@ -65,4 +66,9 @@ struct wlr_xcursor *wlr_xcursor_theme_get_cursor(
int wlr_xcursor_frame(struct wlr_xcursor *cursor, uint32_t time); int wlr_xcursor_frame(struct wlr_xcursor *cursor, uint32_t time);
/**
* Get the name of the resize cursor image for the given edges.
*/
const char *wlr_xcursor_get_resize_name(enum wlr_edges edges);
#endif #endif

View File

@ -155,21 +155,19 @@ void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland,
uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height, uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height,
int32_t hotspot_x, int32_t hotspot_y); int32_t hotspot_x, int32_t hotspot_y);
void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_activate(struct wlr_xwayland_surface *surface,
struct wlr_xwayland_surface *surface, bool activated); bool activated);
void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_configure(struct wlr_xwayland_surface *surface,
struct wlr_xwayland_surface *surface, int16_t x, int16_t y, int16_t x, int16_t y, uint16_t width, uint16_t height);
uint16_t width, uint16_t height);
void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_close(struct wlr_xwayland_surface *surface);
struct wlr_xwayland_surface *surface);
void wlr_xwayland_surface_set_maximized(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_set_maximized(struct wlr_xwayland_surface *surface,
struct wlr_xwayland_surface *surface, bool maximized); bool maximized);
void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland_surface *surface,
struct wlr_xwayland_surface *surface, bool fullscreen); bool fullscreen);
void wlr_xwayland_set_seat(struct wlr_xwayland *xwayland, void wlr_xwayland_set_seat(struct wlr_xwayland *xwayland,
struct wlr_seat *seat); struct wlr_seat *seat);

View File

@ -2,6 +2,7 @@ project(
'wlroots', 'wlroots',
'c', 'c',
license: 'MIT', license: 'MIT',
meson_version: '>=0.43.0',
default_options: [ default_options: [
'c_std=c11', 'c_std=c11',
'warning_level=2', 'warning_level=2',

View File

@ -4,7 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/render/egl.h> #include <wlr/render/egl.h>
#include "render/glapi.h" #include "glapi.h"
// Extension documentation // Extension documentation
// https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_image_base.txt. // https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_image_base.txt.

View File

@ -12,7 +12,7 @@
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "render/gles2.h" #include "render/gles2.h"
#include "render/glapi.h" #include "glapi.h"
struct shaders shaders; struct shaders shaders;

View File

@ -1,14 +1,9 @@
glgen = find_program('../glgen.sh') glgen = find_program('../glgen.sh')
glapi_c = custom_target('glapi.c', glapi = custom_target('glapi',
input: 'glapi.txt', input: 'glapi.txt',
output: '@BASENAME@.c', output: ['@BASENAME@.c', '@BASENAME@.h'],
command: [glgen, '@INPUT@', '@OUTPUT@'], command: [glgen, '@INPUT@', '@OUTPUT0@', '@OUTPUT1@'],
)
glapi_h = custom_target('glapi.h',
input: 'glapi.txt',
output: '@BASENAME@.h',
command: [glgen, '@INPUT@', '@OUTPUT@'],
) )
lib_wlr_render = static_library( lib_wlr_render = static_library(
@ -24,13 +19,13 @@ lib_wlr_render = static_library(
'wlr_renderer.c', 'wlr_renderer.c',
'wlr_texture.c', 'wlr_texture.c',
), ),
glapi_c, glapi[0],
glapi_h, glapi[1],
include_directories: wlr_inc, include_directories: wlr_inc,
dependencies: [glesv2, egl], dependencies: [glesv2, egl],
) )
wlr_render = declare_dependency( wlr_render = declare_dependency(
link_with: lib_wlr_render, link_with: lib_wlr_render,
sources: glapi_h, sources: glapi[1],
) )

View File

@ -466,10 +466,15 @@ void roots_config_destroy(struct roots_config *config) {
struct roots_output_config *roots_config_get_output(struct roots_config *config, struct roots_output_config *roots_config_get_output(struct roots_config *config,
struct wlr_output *output) { struct wlr_output *output) {
struct roots_output_config *o_config; char name[83];
wl_list_for_each(o_config, &config->outputs, link) { snprintf(name, sizeof(name), "%s %s %s", output->make, output->model,
if (strcmp(o_config->name, output->name) == 0) { output->serial);
return o_config;
struct roots_output_config *oc;
wl_list_for_each(oc, &config->outputs, link) {
if (strcmp(oc->name, output->name) == 0 ||
strcmp(oc->name, name) == 0) {
return oc;
} }
} }

View File

@ -8,6 +8,7 @@
#endif #endif
#include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/util/edges.h>
#include "rootston/xcursor.h" #include "rootston/xcursor.h"
#include "rootston/cursor.h" #include "rootston/cursor.h"
@ -37,7 +38,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
double sx, sy; double sx, sy;
switch (cursor->mode) { switch (cursor->mode) {
case ROOTS_CURSOR_PASSTHROUGH: case ROOTS_CURSOR_PASSTHROUGH:
view = view_at(desktop, cursor->cursor->x, cursor->cursor->y, view = desktop_view_at(desktop, cursor->cursor->x, cursor->cursor->y,
&surface, &sx, &sy); &surface, &sx, &sy);
bool set_compositor_cursor = !view && cursor->cursor_client; bool set_compositor_cursor = !view && cursor->cursor_client;
if (view) { if (view) {
@ -71,43 +72,37 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
if (view != NULL) { if (view != NULL) {
double dx = cursor->cursor->x - cursor->offs_x; double dx = cursor->cursor->x - cursor->offs_x;
double dy = cursor->cursor->y - cursor->offs_y; double dy = cursor->cursor->y - cursor->offs_y;
double active_x = view->x; double x = view->x;
double active_y = view->y; double y = view->y;
int width = cursor->view_width; int width = cursor->view_width;
int height = cursor->view_height; int height = cursor->view_height;
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { if (cursor->resize_edges & WLR_EDGE_TOP) {
active_y = cursor->view_y + dy; y = cursor->view_y + dy;
height -= dy; height -= dy;
if (height < 0) { if (height < 1) {
active_y += height; y += height;
} }
} else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { } else if (cursor->resize_edges & WLR_EDGE_BOTTOM) {
height += dy; height += dy;
} }
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { if (cursor->resize_edges & WLR_EDGE_LEFT) {
active_x = cursor->view_x + dx; x = cursor->view_x + dx;
width -= dx; width -= dx;
if (width < 0) { if (width < 1) {
active_x += width; x += width;
} }
} else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { } else if (cursor->resize_edges & WLR_EDGE_RIGHT) {
width += dx; width += dx;
} }
if (width < 0) { if (width < 1) {
width = 0; width = 1;
} }
if (height < 0) { if (height < 1) {
height = 0; height = 1;
} }
if (active_x != view->x || view_move_resize(view, x, y, width, height);
active_y != view->y) {
view_move_resize(view, active_x, active_y,
width, height);
} else {
view_resize(view, width, height);
}
} }
break; break;
case ROOTS_CURSOR_ROTATE: case ROOTS_CURSOR_ROTATE:
@ -137,7 +132,8 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
struct wlr_surface *surface; struct wlr_surface *surface;
double sx, sy; double sx, sy;
struct roots_view *view = view_at(desktop, lx, ly, &surface, &sx, &sy); struct roots_view *view =
desktop_view_at(desktop, lx, ly, &surface, &sx, &sy);
if (state == WLR_BUTTON_PRESSED && if (state == WLR_BUTTON_PRESSED &&
view && view &&
@ -152,14 +148,14 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
case BTN_RIGHT: case BTN_RIGHT:
edges = 0; edges = 0;
if (sx < view->wlr_surface->current->width/2) { if (sx < view->wlr_surface->current->width/2) {
edges |= ROOTS_CURSOR_RESIZE_EDGE_LEFT; edges |= WLR_EDGE_LEFT;
} else { } else {
edges |= ROOTS_CURSOR_RESIZE_EDGE_RIGHT; edges |= WLR_EDGE_RIGHT;
} }
if (sy < view->wlr_surface->current->height/2) { if (sy < view->wlr_surface->current->height/2) {
edges |= ROOTS_CURSOR_RESIZE_EDGE_TOP; edges |= WLR_EDGE_TOP;
} else { } else {
edges |= ROOTS_CURSOR_RESIZE_EDGE_BOTTOM; edges |= WLR_EDGE_BOTTOM;
} }
roots_seat_begin_resize(seat, view, edges); roots_seat_begin_resize(seat, view, edges);
break; break;
@ -237,7 +233,7 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
return; return;
} }
double sx, sy; double sx, sy;
view_at(desktop, lx, ly, &surface, &sx, &sy); desktop_view_at(desktop, lx, ly, &surface, &sx, &sy);
uint32_t serial = 0; uint32_t serial = 0;
if (surface) { if (surface) {
@ -291,7 +287,7 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
} }
double sx, sy; double sx, sy;
view_at(desktop, lx, ly, &surface, &sx, &sy); desktop_view_at(desktop, lx, ly, &surface, &sx, &sy);
if (surface) { if (surface) {
wlr_seat_touch_point_focus(cursor->seat->seat, surface, wlr_seat_touch_point_focus(cursor->seat->seat, surface,

View File

@ -13,7 +13,6 @@
#include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <server-decoration-protocol.h>
#include "rootston/server.h" #include "rootston/server.h"
#include "rootston/seat.h" #include "rootston/seat.h"
#include "rootston/xcursor.h" #include "rootston/xcursor.h"
@ -36,7 +35,7 @@ static void view_update_output(const struct roots_view *view,
struct wlr_box box; struct wlr_box box;
view_get_box(view, &box); view_get_box(view, &box);
wl_list_for_each(output, &desktop->outputs, link) { wl_list_for_each(output, &desktop->outputs, link) {
bool intersected = before->x != -1 && wlr_output_layout_intersects( bool intersected = before != NULL && wlr_output_layout_intersects(
desktop->layout, output->wlr_output, desktop->layout, output->wlr_output,
before->x, before->y, before->x + before->width, before->x, before->y, before->x + before->width,
before->y + before->height); before->y + before->height);
@ -53,6 +52,10 @@ static void view_update_output(const struct roots_view *view,
} }
void view_move(struct roots_view *view, double x, double y) { void view_move(struct roots_view *view, double x, double y) {
if (view->x == x && view->y == y) {
return;
}
struct wlr_box before; struct wlr_box before;
view_get_box(view, &before); view_get_box(view, &before);
if (view->move) { if (view->move) {
@ -61,6 +64,7 @@ void view_move(struct roots_view *view, double x, double y) {
view->x = x; view->x = x;
view->y = y; view->y = y;
} }
view_update_output(view, &before);
} }
void view_activate(struct roots_view *view, bool activate) { void view_activate(struct roots_view *view, bool activate) {
@ -80,15 +84,41 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) {
void view_move_resize(struct roots_view *view, double x, double y, void view_move_resize(struct roots_view *view, double x, double y,
uint32_t width, uint32_t height) { uint32_t width, uint32_t height) {
bool update_x = x != view->x;
bool update_y = y != view->y;
if (!update_x && !update_y) {
view_resize(view, width, height);
return;
}
if (view->move_resize) { if (view->move_resize) {
view->move_resize(view, x, y, width, height); view->move_resize(view, x, y, width, height);
return; return;
} }
view_move(view, x, y); 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 = width;
view->pending_move_resize.height = height;
view_resize(view, width, height); view_resize(view, width, height);
} }
static struct wlr_output *view_get_output(struct roots_view *view) {
struct wlr_box view_box;
view_get_box(view, &view_box);
double output_x, output_y;
wlr_output_layout_closest_point(view->desktop->layout, NULL,
view->x + (double)view_box.width/2,
view->y + (double)view_box.height/2,
&output_x, &output_y);
return wlr_output_layout_output_at(view->desktop->layout, output_x,
output_y);
}
void view_maximize(struct roots_view *view, bool maximized) { void view_maximize(struct roots_view *view, bool maximized) {
if (view->maximized == maximized) { if (view->maximized == maximized) {
return; return;
@ -109,13 +139,7 @@ void view_maximize(struct roots_view *view, bool maximized) {
view->saved.width = view_box.width; view->saved.width = view_box.width;
view->saved.height = view_box.height; view->saved.height = view_box.height;
double output_x, output_y; struct wlr_output *output = view_get_output(view);
wlr_output_layout_closest_point(view->desktop->layout, NULL,
view->x + (double)view_box.width/2,
view->y + (double)view_box.height/2,
&output_x, &output_y);
struct wlr_output *output = wlr_output_layout_output_at(
view->desktop->layout, output_x, output_y);
struct wlr_box *output_box = struct wlr_box *output_box =
wlr_output_layout_get_box(view->desktop->layout, output); wlr_output_layout_get_box(view->desktop->layout, output);
@ -133,6 +157,59 @@ void view_maximize(struct roots_view *view, bool maximized) {
} }
} }
void view_set_fullscreen(struct roots_view *view, bool fullscreen,
struct wlr_output *output) {
bool was_fullscreen = view->fullscreen_output != NULL;
if (was_fullscreen == fullscreen) {
// TODO: support changing the output?
return;
}
// TODO: check if client is focused?
if (view->set_fullscreen) {
view->set_fullscreen(view, fullscreen);
}
if (!was_fullscreen && fullscreen) {
if (output == NULL) {
output = view_get_output(view);
}
struct roots_output *roots_output =
desktop_output_from_wlr_output(view->desktop, output);
if (roots_output == NULL) {
return;
}
struct wlr_box view_box;
view_get_box(view, &view_box);
view->saved.x = view->x;
view->saved.y = view->y;
view->saved.rotation = view->rotation;
view->saved.width = view_box.width;
view->saved.height = view_box.height;
struct wlr_box *output_box =
wlr_output_layout_get_box(view->desktop->layout, output);
view_move_resize(view, output_box->x, output_box->y, output_box->width,
output_box->height);
view->rotation = 0;
roots_output->fullscreen_view = view;
view->fullscreen_output = roots_output;
}
if (was_fullscreen && !fullscreen) {
view_move_resize(view, view->saved.x, view->saved.y, view->saved.width,
view->saved.height);
view->rotation = view->saved.rotation;
view->fullscreen_output->fullscreen_view = NULL;
view->fullscreen_output = NULL;
}
}
void view_close(struct roots_view *view) { void view_close(struct roots_view *view) {
if (view->close) { if (view->close) {
view->close(view); view->close(view);
@ -181,6 +258,10 @@ bool view_center(struct roots_view *view) {
void view_destroy(struct roots_view *view) { void view_destroy(struct roots_view *view) {
wl_signal_emit(&view->events.destroy, view); wl_signal_emit(&view->events.destroy, view);
if (view->fullscreen_output) {
view->fullscreen_output->fullscreen_view = NULL;
}
free(view); free(view);
} }
@ -198,19 +279,14 @@ void view_setup(struct roots_view *view) {
} }
view_center(view); view_center(view);
struct wlr_box before; view_update_output(view, NULL);
view_get_box(view, &before);
view_update_output(view, &before);
} }
struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, static bool view_at(struct roots_view *view, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy) { struct wlr_surface **surface, double *sx, double *sy) {
struct roots_view *view;
wl_list_for_each(view, &desktop->views, link) {
if (view->type == ROOTS_WL_SHELL_VIEW && if (view->type == ROOTS_WL_SHELL_VIEW &&
view->wl_shell_surface->state == view->wl_shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP) {
WLR_WL_SHELL_SURFACE_STATE_POPUP) { return false;
continue;
} }
double view_sx = lx - view->x; double view_sx = lx - view->x;
@ -244,7 +320,7 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
*sx = view_sx - popup_sx; *sx = view_sx - popup_sx;
*sy = view_sy - popup_sy; *sy = view_sy - popup_sy;
*surface = popup->surface; *surface = popup->surface;
return view; return true;
} }
} }
@ -258,7 +334,7 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
*sx = view_sx - popup_sx; *sx = view_sx - popup_sx;
*sy = view_sy - popup_sy; *sy = view_sy - popup_sy;
*surface = popup->surface; *surface = popup->surface;
return view; return true;
} }
} }
@ -270,16 +346,40 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
*sx = view_sx - sub_x; *sx = view_sx - sub_x;
*sy = view_sy - sub_y; *sy = view_sy - sub_y;
*surface = subsurface->surface; *surface = subsurface->surface;
return view; return true;
} }
if (wlr_box_contains_point(&box, view_sx, view_sy) && if (wlr_box_contains_point(&box, view_sx, view_sy) &&
pixman_region32_contains_point( pixman_region32_contains_point(&view->wlr_surface->current->input,
&view->wlr_surface->current->input,
view_sx, view_sy, NULL)) { view_sx, view_sy, NULL)) {
*sx = view_sx; *sx = view_sx;
*sy = view_sy; *sy = view_sy;
*surface = view->wlr_surface; *surface = view->wlr_surface;
return true;
}
return false;
}
struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
double ly, struct wlr_surface **surface, double *sx, double *sy) {
struct wlr_output *wlr_output =
wlr_output_layout_output_at(desktop->layout, lx, ly);
if (wlr_output != NULL) {
struct roots_output *output =
desktop_output_from_wlr_output(desktop, wlr_output);
if (output != NULL && output->fullscreen_view != NULL) {
if (view_at(output->fullscreen_view, lx, ly, surface, sx, sy)) {
return output->fullscreen_view;
} else {
return NULL;
}
}
}
struct roots_view *view;
wl_list_for_each(view, &desktop->views, link) {
if (view_at(view, lx, ly, surface, sx, sy)) {
return view; return view;
} }
} }
@ -367,7 +467,7 @@ struct roots_desktop *desktop_create(struct roots_server *server,
wlr_server_decoration_manager_create(server->wl_display); wlr_server_decoration_manager_create(server->wl_display);
wlr_server_decoration_manager_set_default_mode( wlr_server_decoration_manager_set_default_mode(
desktop->server_decoration_manager, desktop->server_decoration_manager,
ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_CLIENT); WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT);
return desktop; return desktop;
} }
@ -375,3 +475,14 @@ struct roots_desktop *desktop_create(struct roots_server *server,
void desktop_destroy(struct roots_desktop *desktop) { void desktop_destroy(struct roots_desktop *desktop) {
// TODO // TODO
} }
struct roots_output *desktop_output_from_wlr_output(
struct roots_desktop *desktop, struct wlr_output *output) {
struct roots_output *roots_output;
wl_list_for_each(roots_output, &desktop->outputs, link) {
if (roots_output->wlr_output == output) {
return roots_output;
}
}
return NULL;
}

View File

@ -95,6 +95,12 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard,
if (focus != NULL) { if (focus != NULL) {
view_close(focus); view_close(focus);
} }
} else if (strcmp(command, "fullscreen") == 0) {
struct roots_view *focus = roots_seat_get_focus(seat);
if (focus != NULL) {
bool is_fullscreen = focus->fullscreen_output != NULL;
view_set_fullscreen(focus, !is_fullscreen, NULL);
}
} else if (strcmp(command, "next_window") == 0) { } else if (strcmp(command, "next_window") == 0) {
roots_seat_cycle_focus(seat); roots_seat_cycle_focus(seat);
} else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) {
@ -106,6 +112,11 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard,
} else if (pid == 0) { } else if (pid == 0) {
execl("/bin/sh", "/bin/sh", "-c", shell_cmd, (void *)NULL); execl("/bin/sh", "/bin/sh", "-c", shell_cmd, (void *)NULL);
} }
} else if (strcmp(command, "maximize") == 0) {
struct roots_view *focus = roots_seat_get_focus(seat);
if (focus != NULL) {
view_maximize(focus, !focus->maximized);
}
} else { } else {
wlr_log(L_ERROR, "unknown binding command: %s", command); wlr_log(L_ERROR, "unknown binding command: %s", command);
} }

View File

@ -8,7 +8,6 @@ sources = [
'main.c', 'main.c',
'output.c', 'output.c',
'seat.c', 'seat.c',
'xcursor.c',
'xdg_shell_v6.c', 'xdg_shell_v6.c',
'wl_shell.c', 'wl_shell.c',
] ]

View File

@ -2,6 +2,7 @@
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <GLES2/gl2.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
@ -13,10 +14,6 @@
#include "rootston/desktop.h" #include "rootston/desktop.h"
#include "rootston/config.h" #include "rootston/config.h"
static inline int64_t timespec_to_msec(const struct timespec *a) {
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
}
/** /**
* Rotate a child's position relative to a parent. The parent size is (pw, ph), * Rotate a child's position relative to a parent. The parent size is (pw, ph),
* the child position is (*sx, *sy) and its size is (sw, sh). * the child position is (*sx, *sy) and its size is (sw, sh).
@ -75,12 +72,7 @@ static void render_surface(struct wlr_surface *surface,
wlr_render_with_matrix(desktop->server->renderer, surface->texture, wlr_render_with_matrix(desktop->server->renderer, surface->texture,
&matrix); &matrix);
struct wlr_frame_callback *cb, *cnext; wlr_surface_send_frame_done(surface, when);
wl_list_for_each_safe(cb, cnext,
&surface->current->frame_callback_list, link) {
wl_callback_send_done(cb->resource, timespec_to_msec(when));
wl_resource_destroy(cb->resource);
}
} }
struct wlr_subsurface *subsurface; struct wlr_subsurface *subsurface;
@ -174,6 +166,22 @@ static void render_view(struct roots_view *view, struct roots_desktop *desktop,
} }
} }
static bool has_standalone_surface(struct roots_view *view) {
if (!wl_list_empty(&view->wlr_surface->subsurface_list)) {
return false;
}
switch (view->type) {
case ROOTS_XDG_SHELL_V6_VIEW:
return wl_list_empty(&view->xdg_surface_v6->popups);
case ROOTS_WL_SHELL_VIEW:
return wl_list_empty(&view->wl_shell_surface->popups);
case ROOTS_XWAYLAND_VIEW:
return true;
}
return true;
}
static void output_frame_notify(struct wl_listener *listener, void *data) { static void output_frame_notify(struct wl_listener *listener, void *data) {
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
struct roots_output *output = wl_container_of(listener, output, frame); struct roots_output *output = wl_container_of(listener, output, frame);
@ -186,6 +194,37 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
wlr_output_make_current(wlr_output); wlr_output_make_current(wlr_output);
wlr_renderer_begin(server->renderer, wlr_output); wlr_renderer_begin(server->renderer, wlr_output);
if (output->fullscreen_view != NULL) {
// Make sure the view is centered on screen
const struct wlr_box *output_box =
wlr_output_layout_get_box(desktop->layout, wlr_output);
struct wlr_box view_box;
view_get_box(output->fullscreen_view, &view_box);
double view_x = (double)(output_box->width - view_box.width) / 2 +
output_box->x;
double view_y = (double)(output_box->height - view_box.height) / 2 +
output_box->y;
view_move(output->fullscreen_view, view_x, view_y);
if (has_standalone_surface(output->fullscreen_view)) {
wlr_output_set_fullscreen_surface(wlr_output,
output->fullscreen_view->wlr_surface);
} else {
wlr_output_set_fullscreen_surface(wlr_output, NULL);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
render_view(output->fullscreen_view, desktop, wlr_output, &now);
}
wlr_renderer_end(server->renderer);
wlr_output_swap_buffers(wlr_output);
output->last_frame = desktop->last_frame = now;
return;
} else {
wlr_output_set_fullscreen_surface(wlr_output, NULL);
}
struct roots_view *view; struct roots_view *view;
wl_list_for_each_reverse(view, &desktop->views, link) { wl_list_for_each_reverse(view, &desktop->views, link) {
render_view(view, desktop, wlr_output, &now); render_view(view, desktop, wlr_output, &now);
@ -252,7 +291,7 @@ void output_add_notify(struct wl_listener *listener, void *data) {
struct roots_config *config = desktop->config; struct roots_config *config = desktop->config;
wlr_log(L_DEBUG, "Output '%s' added", wlr_output->name); wlr_log(L_DEBUG, "Output '%s' added", wlr_output->name);
wlr_log(L_DEBUG, "%s %s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make, wlr_log(L_DEBUG, "'%s %s %s' %"PRId32"mm x %"PRId32"mm", wlr_output->make,
wlr_output->model, wlr_output->serial, wlr_output->phys_width, wlr_output->model, wlr_output->serial, wlr_output->phys_width,
wlr_output->phys_height); wlr_output->phys_height);
if (wl_list_length(&wlr_output->modes) > 0) { if (wl_list_length(&wlr_output->modes) > 0) {
@ -275,10 +314,10 @@ void output_add_notify(struct wl_listener *listener, void *data) {
if (output_config->mode.width) { if (output_config->mode.width) {
set_mode(wlr_output, output_config); set_mode(wlr_output, output_config);
} }
wlr_output->scale = output_config->scale; wlr_output_set_scale(wlr_output, output_config->scale);
wlr_output_transform(wlr_output, output_config->transform); wlr_output_transform(wlr_output, output_config->transform);
wlr_output_layout_add(desktop->layout, wlr_output_layout_add(desktop->layout, wlr_output, output_config->x,
wlr_output, output_config->x, output_config->y); output_config->y);
} else { } else {
wlr_output_layout_add_auto(desktop->layout, wlr_output); wlr_output_layout_add_auto(desktop->layout, wlr_output);
} }

View File

@ -44,4 +44,5 @@ meta-key = Logo
[bindings] [bindings]
Logo+Shift+e = exit Logo+Shift+e = exit
Logo+q = close Logo+q = close
Logo+m = maximize
Alt+Tab = next_window Alt+Tab = next_window

View File

@ -661,8 +661,9 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
view_maximize(view, false); view_maximize(view, false);
wlr_seat_pointer_clear_focus(seat->seat); wlr_seat_pointer_clear_focus(seat->seat);
const char *resize_name = wlr_xcursor_get_resize_name(edges);
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
roots_xcursor_get_resize_name(edges), seat->cursor->cursor); resize_name, seat->cursor->cursor);
} }
void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) {

View File

@ -50,15 +50,24 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
roots_seat_begin_resize(seat, view, e->edges); roots_seat_begin_resize(seat, view, e->edges);
} }
static void handle_request_set_maximized(struct wl_listener *listener, static void handle_request_maximize(struct wl_listener *listener,
void *data) { void *data) {
struct roots_wl_shell_surface *roots_surface = struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, request_set_maximized); wl_container_of(listener, roots_surface, request_maximize);
struct roots_view *view = roots_surface->view; struct roots_view *view = roots_surface->view;
//struct wlr_wl_shell_surface_set_maximized_event *e = data; //struct wlr_wl_shell_surface_maximize_event *e = data;
view_maximize(view, true); view_maximize(view, true);
} }
static void handle_request_fullscreen(struct wl_listener *listener,
void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, request_fullscreen);
struct roots_view *view = roots_surface->view;
struct wlr_wl_shell_surface_set_fullscreen_event *e = data;
view_set_fullscreen(view, true, e->output);
}
static void handle_set_state(struct wl_listener *listener, void *data) { static void handle_set_state(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface = struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, set_state); wl_container_of(listener, roots_surface, set_state);
@ -68,10 +77,31 @@ static void handle_set_state(struct wl_listener *listener, void *data) {
surface->state != WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED) { surface->state != WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED) {
view_maximize(view, false); view_maximize(view, false);
} }
if (view->fullscreen_output != NULL &&
surface->state != WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN) {
view_set_fullscreen(view, false, NULL);
}
} }
static void handle_surface_commit(struct wl_listener *listener, void *data) { static void handle_surface_commit(struct wl_listener *listener, void *data) {
// TODO do we need to do anything here? struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, surface_commit);
struct roots_view *view = roots_surface->view;
struct wlr_surface *wlr_surface = view->wlr_surface;
int width = wlr_surface->current->width;
int height = wlr_surface->current->height;
if (view->pending_move_resize.update_x) {
view->x = view->pending_move_resize.x +
view->pending_move_resize.width - width;
view->pending_move_resize.update_x = false;
}
if (view->pending_move_resize.update_y) {
view->y = view->pending_move_resize.y +
view->pending_move_resize.height - height;
view->pending_move_resize.update_y = false;
}
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
@ -80,7 +110,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->destroy.link);
wl_list_remove(&roots_surface->request_move.link); wl_list_remove(&roots_surface->request_move.link);
wl_list_remove(&roots_surface->request_resize.link); wl_list_remove(&roots_surface->request_resize.link);
wl_list_remove(&roots_surface->request_set_maximized.link); wl_list_remove(&roots_surface->request_maximize.link);
wl_list_remove(&roots_surface->request_fullscreen.link);
wl_list_remove(&roots_surface->set_state.link); wl_list_remove(&roots_surface->set_state.link);
wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->surface_commit.link);
wl_list_remove(&roots_surface->view->link); wl_list_remove(&roots_surface->view->link);
@ -109,14 +140,17 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
roots_surface->request_resize.notify = handle_request_resize; roots_surface->request_resize.notify = handle_request_resize;
wl_signal_add(&surface->events.request_resize, wl_signal_add(&surface->events.request_resize,
&roots_surface->request_resize); &roots_surface->request_resize);
roots_surface->request_set_maximized.notify = handle_request_set_maximized; roots_surface->request_maximize.notify = handle_request_maximize;
wl_signal_add(&surface->events.request_set_maximized, wl_signal_add(&surface->events.request_maximize,
&roots_surface->request_set_maximized); &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->set_state.notify = handle_set_state; roots_surface->set_state.notify = handle_set_state;
wl_signal_add(&surface->events.set_state, &roots_surface->set_state); wl_signal_add(&surface->events.set_state, &roots_surface->set_state);
roots_surface->surface_commit.notify = handle_surface_commit; roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit, wl_signal_add(&surface->events.commit, &roots_surface->surface_commit);
&roots_surface->surface_commit);
struct roots_view *view = calloc(1, sizeof(struct roots_view)); struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (!view) { if (!view) {

View File

@ -1,28 +0,0 @@
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <string.h>
#include "rootston/xcursor.h"
#include "rootston/input.h"
const char *roots_xcursor_get_resize_name(uint32_t edges) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
return "ne-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
return "nw-resize";
}
return "n-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
return "se-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
return "sw-resize";
}
return "s-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
return "e-resize";
} else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
return "w-resize";
}
return "se-resize"; // fallback
}

View File

@ -12,11 +12,11 @@
static void get_size(const struct roots_view *view, struct wlr_box *box) { static void get_size(const struct roots_view *view, struct wlr_box *box) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surf->geometry->width > 0 && surf->geometry->height > 0) { if (surface->geometry->width > 0 && surface->geometry->height > 0) {
box->width = surf->geometry->width; box->width = surface->geometry->width;
box->height = surf->geometry->height; box->height = surface->geometry->height;
} else { } else {
box->width = view->wlr_surface->current->width; box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height; box->height = view->wlr_surface->current->height;
@ -25,20 +25,19 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) {
static void activate(struct roots_view *view, bool active) { static void activate(struct roots_view *view, bool active) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
wlr_xdg_toplevel_v6_set_activated(surf, active); wlr_xdg_toplevel_v6_set_activated(surface, active);
} }
} }
static void apply_size_constraints(struct wlr_xdg_surface_v6 *surf, static void apply_size_constraints(struct wlr_xdg_surface_v6 *surface,
uint32_t width, uint32_t height, uint32_t *dest_width, uint32_t width, uint32_t height, uint32_t *dest_width,
uint32_t *dest_height) { uint32_t *dest_height) {
*dest_width = width; *dest_width = width;
*dest_height = height; *dest_height = height;
struct wlr_xdg_toplevel_v6_state *state = struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel_state->current;
&surf->toplevel_state->current;
if (width < state->min_width) { if (width < state->min_width) {
*dest_width = state->min_width; *dest_width = state->min_width;
} else if (state->max_width > 0 && } else if (state->max_width > 0 &&
@ -55,39 +54,57 @@ static void apply_size_constraints(struct wlr_xdg_surface_v6 *surf,
static void resize(struct roots_view *view, uint32_t width, uint32_t height) { static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surf->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
return; return;
} }
uint32_t contrained_width, contrained_height; uint32_t constrained_width, constrained_height;
apply_size_constraints(surf, width, height, &contrained_width, apply_size_constraints(surface, width, height, &constrained_width,
&contrained_height); &constrained_height);
wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height); wlr_xdg_toplevel_v6_set_size(surface, constrained_width,
constrained_height);
} }
static void move_resize(struct roots_view *view, double x, double y, static void move_resize(struct roots_view *view, double x, double y,
uint32_t width, uint32_t height) { uint32_t width, uint32_t height) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; struct roots_xdg_surface_v6 *roots_surface = view->roots_xdg_surface_v6;
if (surf->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
return; return;
} }
uint32_t contrained_width, contrained_height; bool update_x = x != view->x;
apply_size_constraints(surf, width, height, &contrained_width, bool update_y = y != view->y;
&contrained_height);
x = x + width - contrained_width; uint32_t constrained_width, constrained_height;
y = y + height - contrained_height; apply_size_constraints(surface, width, height, &constrained_width,
&constrained_height);
// TODO: we should wait for an ack_configure event before updating the if (update_x) {
// position 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_v6_set_size(surface, constrained_width,
constrained_height);
if (serial > 0) {
roots_surface->pending_move_resize_configure_serial = serial;
} else {
view->x = x; view->x = x;
view->y = y; view->y = y;
}
wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height);
} }
static void maximize(struct roots_view *view, bool maximized) { static void maximize(struct roots_view *view, bool maximized) {
@ -100,11 +117,21 @@ static void maximize(struct roots_view *view, bool maximized) {
wlr_xdg_toplevel_v6_set_maximized(surface, maximized); wlr_xdg_toplevel_v6_set_maximized(surface, maximized);
} }
static void set_fullscreen(struct roots_view *view, bool fullscreen) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
return;
}
wlr_xdg_toplevel_v6_set_fullscreen(surface, fullscreen);
}
static void close(struct roots_view *view) { static void close(struct roots_view *view) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
wlr_xdg_toplevel_v6_send_close(surf); wlr_xdg_toplevel_v6_send_close(surface);
} }
} }
@ -150,12 +177,46 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) {
view_maximize(view, surface->toplevel_state->next.maximized); view_maximize(view, surface->toplevel_state->next.maximized);
} }
static void handle_request_fullscreen(struct wl_listener *listener,
void *data) {
struct roots_xdg_surface_v6 *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, request_fullscreen);
struct roots_view *view = roots_xdg_surface->view;
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
struct wlr_xdg_toplevel_v6_set_fullscreen_event *e = data;
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
return;
}
view_set_fullscreen(view, e->fullscreen, e->output);
}
static void handle_commit(struct wl_listener *listener, void *data) { static void handle_commit(struct wl_listener *listener, void *data) {
//struct roots_xdg_surface_v6 *roots_xdg_surface = struct roots_xdg_surface_v6 *roots_surface =
// wl_container_of(listener, roots_xdg_surface, commit); wl_container_of(listener, roots_surface, commit);
//struct roots_view *view = roots_xdg_surface->view; struct roots_view *view = roots_surface->view;
//struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
// TODO
uint32_t pending_serial =
roots_surface->pending_move_resize_configure_serial;
if (pending_serial > 0 && pending_serial >= surface->configure_serial) {
struct wlr_box size;
get_size(view, &size);
if (view->pending_move_resize.update_x) {
view->x = view->pending_move_resize.x +
view->pending_move_resize.width - size.width;
}
if (view->pending_move_resize.update_y) {
view->y = view->pending_move_resize.y +
view->pending_move_resize.height - size.height;
}
if (pending_serial == surface->configure_serial) {
roots_surface->pending_move_resize_configure_serial = 0;
}
}
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
@ -203,6 +264,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
roots_surface->request_maximize.notify = handle_request_maximize; roots_surface->request_maximize.notify = handle_request_maximize;
wl_signal_add(&surface->events.request_maximize, wl_signal_add(&surface->events.request_maximize,
&roots_surface->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);
struct roots_view *view = calloc(1, sizeof(struct roots_view)); struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (!view) { if (!view) {
@ -218,6 +282,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->resize = resize; view->resize = resize;
view->move_resize = move_resize; view->move_resize = move_resize;
view->maximize = maximize; view->maximize = maximize;
view->set_fullscreen = set_fullscreen;
view->close = close; view->close = close;
roots_surface->view = view; roots_surface->view = view;
view_init(view, desktop); view_init(view, desktop);

View File

@ -11,8 +11,7 @@
static void activate(struct roots_view *view, bool active) { static void activate(struct roots_view *view, bool active) {
assert(view->type == ROOTS_XWAYLAND_VIEW); assert(view->type == ROOTS_XWAYLAND_VIEW);
struct wlr_xwayland *xwayland = view->desktop->xwayland; wlr_xwayland_surface_activate(view->xwayland_surface, active);
wlr_xwayland_surface_activate(xwayland, view->xwayland_surface, active);
} }
static void move(struct roots_view *view, double x, double y) { static void move(struct roots_view *view, double x, double y) {
@ -20,8 +19,8 @@ static void move(struct roots_view *view, double x, double y) {
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
view->x = x; view->x = x;
view->y = y; view->y = y;
wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, wlr_xwayland_surface_configure(xwayland_surface, x, y,
x, y, xwayland_surface->width, xwayland_surface->height); xwayland_surface->width, xwayland_surface->height);
} }
static void apply_size_constraints( static void apply_size_constraints(
@ -52,13 +51,12 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
assert(view->type == ROOTS_XWAYLAND_VIEW); assert(view->type == ROOTS_XWAYLAND_VIEW);
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
uint32_t contrained_width, contrained_height; uint32_t constrained_width, constrained_height;
apply_size_constraints(xwayland_surface, width, height, &contrained_width, apply_size_constraints(xwayland_surface, width, height, &constrained_width,
&contrained_height); &constrained_height);
wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, wlr_xwayland_surface_configure(xwayland_surface, xwayland_surface->x,
xwayland_surface->x, xwayland_surface->y, contrained_width, xwayland_surface->y, constrained_width, constrained_height);
contrained_height);
} }
static void move_resize(struct roots_view *view, double x, double y, static void move_resize(struct roots_view *view, double x, double y,
@ -66,30 +64,46 @@ static void move_resize(struct roots_view *view, double x, double y,
assert(view->type == ROOTS_XWAYLAND_VIEW); assert(view->type == ROOTS_XWAYLAND_VIEW);
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
uint32_t contrained_width, contrained_height; bool update_x = x != view->x;
apply_size_constraints(xwayland_surface, width, height, &contrained_width, bool update_y = y != view->y;
&contrained_height);
x = x + width - contrained_width; uint32_t constrained_width, constrained_height;
y = y + height - contrained_height; apply_size_constraints(xwayland_surface, width, height, &constrained_width,
&constrained_height);
view->x = x; if (update_x) {
view->y = y; x = x + width - constrained_width;
}
if (update_y) {
y = y + height - constrained_height;
}
wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, view->pending_move_resize.update_x = update_x;
x, y, contrained_width, contrained_height); 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;
wlr_xwayland_surface_configure(xwayland_surface, x, y, constrained_width,
constrained_height);
} }
static void close(struct roots_view *view) { static void close(struct roots_view *view) {
assert(view->type == ROOTS_XWAYLAND_VIEW); assert(view->type == ROOTS_XWAYLAND_VIEW);
wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface); wlr_xwayland_surface_close(view->xwayland_surface);
} }
static void maximize(struct roots_view *view, bool maximized) { static void maximize(struct roots_view *view, bool maximized) {
assert(view->type == ROOTS_XWAYLAND_VIEW); assert(view->type == ROOTS_XWAYLAND_VIEW);
wlr_xwayland_surface_set_maximized(view->desktop->xwayland, wlr_xwayland_surface_set_maximized(view->xwayland_surface, maximized);
view->xwayland_surface, maximized); }
static void set_fullscreen(struct roots_view *view, bool fullscreen) {
assert(view->type == ROOTS_XWAYLAND_VIEW);
wlr_xwayland_surface_set_fullscreen(view->xwayland_surface, fullscreen);
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
@ -121,8 +135,8 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
roots_surface->view->x = (double)event->x; roots_surface->view->x = (double)event->x;
roots_surface->view->y = (double)event->y; roots_surface->view->y = (double)event->y;
wlr_xwayland_surface_configure(roots_surface->view->desktop->xwayland, wlr_xwayland_surface_configure(xwayland_surface, event->x, event->y,
xwayland_surface, event->x, event->y, event->width, event->height); event->width, event->height);
} }
static struct roots_seat *guess_seat_for_view(struct roots_view *view) { static struct roots_seat *guess_seat_for_view(struct roots_view *view) {
@ -175,6 +189,37 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) {
view_maximize(view, maximized); view_maximize(view, maximized);
} }
static void handle_request_fullscreen(struct wl_listener *listener,
void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, request_fullscreen);
struct roots_view *view = roots_surface->view;
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
view_set_fullscreen(view, xwayland_surface->fullscreen, NULL);
}
static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, surface_commit);
struct roots_view *view = roots_surface->view;
struct wlr_surface *wlr_surface = view->wlr_surface;
int width = wlr_surface->current->width;
int height = wlr_surface->current->height;
if (view->pending_move_resize.update_x) {
view->x = view->pending_move_resize.x +
view->pending_move_resize.width - width;
view->pending_move_resize.update_x = false;
}
if (view->pending_move_resize.update_y) {
view->y = view->pending_move_resize.y +
view->pending_move_resize.height - height;
view->pending_move_resize.update_y = false;
}
}
static void handle_map_notify(struct wl_listener *listener, void *data) { static void handle_map_notify(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface = struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, map_notify); wl_container_of(listener, roots_surface, map_notify);
@ -186,6 +231,10 @@ static void handle_map_notify(struct wl_listener *listener, void *data) {
view->x = (double)xsurface->x; view->x = (double)xsurface->x;
view->y = (double)xsurface->y; view->y = (double)xsurface->y;
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&xsurface->surface->events.commit,
&roots_surface->surface_commit);
wl_list_insert(&desktop->views, &view->link); wl_list_insert(&desktop->views, &view->link);
} }
@ -194,6 +243,8 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) {
wl_container_of(listener, roots_surface, unmap_notify); wl_container_of(listener, roots_surface, unmap_notify);
roots_surface->view->wlr_surface = NULL; roots_surface->view->wlr_surface = NULL;
wl_list_remove(&roots_surface->surface_commit.link);
wl_list_remove(&roots_surface->view->link); wl_list_remove(&roots_surface->view->link);
} }
@ -228,6 +279,13 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
roots_surface->request_maximize.notify = handle_request_maximize; roots_surface->request_maximize.notify = handle_request_maximize;
wl_signal_add(&surface->events.request_maximize, wl_signal_add(&surface->events.request_maximize,
&roots_surface->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->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit,
&roots_surface->surface_commit);
struct roots_view *view = calloc(1, sizeof(struct roots_view)); struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (view == NULL) { if (view == NULL) {
@ -245,6 +303,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->move = move; view->move = move;
view->move_resize = move_resize; view->move_resize = move_resize;
view->maximize = maximize; view->maximize = maximize;
view->set_fullscreen = set_fullscreen;
view->close = close; view->close = close;
roots_surface->view = view; roots_surface->view = view;
view_init(view, desktop); view_init(view, desktop);

View File

@ -52,6 +52,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) {
static void wlr_output_send_current_mode_to_resource( static void wlr_output_send_current_mode_to_resource(
struct wl_resource *resource) { struct wl_resource *resource) {
assert(resource);
struct wlr_output *output = wl_resource_get_user_data(resource); struct wlr_output *output = wl_resource_get_user_data(resource);
assert(output); assert(output);
const uint32_t version = wl_resource_get_version(resource); const uint32_t version = wl_resource_get_version(resource);
@ -119,7 +120,6 @@ struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output,
struct wl_global *wl_global = wl_global_create(display, struct wl_global *wl_global = wl_global_create(display,
&wl_output_interface, 3, wlr_output, wl_output_bind); &wl_output_interface, 3, wlr_output, wl_output_bind);
wlr_output->wl_global = wl_global; wlr_output->wl_global = wl_global;
wl_list_init(&wlr_output->wl_resources);
return wl_global; return wl_global;
} }
@ -155,6 +155,7 @@ bool wlr_output_set_mode(struct wlr_output *output,
bool result = output->impl->set_mode(output, mode); bool result = output->impl->set_mode(output, mode);
if (result) { if (result) {
wlr_output_update_matrix(output); wlr_output_update_matrix(output);
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) { wl_resource_for_each(resource, &output->wl_resources) {
wlr_output_send_current_mode_to_resource(resource); wlr_output_send_current_mode_to_resource(resource);
@ -168,21 +169,27 @@ void wlr_output_update_size(struct wlr_output *output, int32_t width,
if (output->width == width && output->height == height) { if (output->width == width && output->height == height) {
return; return;
} }
output->width = width; output->width = width;
output->height = height; output->height = height;
wlr_output_update_matrix(output); wlr_output_update_matrix(output);
if (output->wl_global != NULL) {
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) { wl_resource_for_each(resource, &output->wl_resources) {
wlr_output_send_current_mode_to_resource(resource); wlr_output_send_current_mode_to_resource(resource);
} }
} }
}
void wlr_output_transform(struct wlr_output *output, void wlr_output_transform(struct wlr_output *output,
enum wl_output_transform transform) { enum wl_output_transform transform) {
output->impl->transform(output, transform); output->impl->transform(output, transform);
wlr_output_update_matrix(output); wlr_output_update_matrix(output);
// TODO: only send geometry and done
struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) {
wl_output_send_to_resource(resource);
}
} }
void wlr_output_set_position(struct wlr_output *output, int32_t lx, void wlr_output_set_position(struct wlr_output *output, int32_t lx,
@ -194,6 +201,21 @@ void wlr_output_set_position(struct wlr_output *output, int32_t lx,
output->lx = lx; output->lx = lx;
output->ly = ly; output->ly = ly;
// TODO: only send geometry and done
struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) {
wl_output_send_to_resource(resource);
}
}
void wlr_output_set_scale(struct wlr_output *output, uint32_t scale) {
if (output->scale == scale) {
return;
}
output->scale = scale;
// TODO: only send mode and done
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) { wl_resource_for_each(resource, &output->wl_resources) {
wl_output_send_to_resource(resource); wl_output_send_to_resource(resource);
@ -209,6 +231,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
output->transform = WL_OUTPUT_TRANSFORM_NORMAL; output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
output->scale = 1; output->scale = 1;
wl_list_init(&output->cursors); wl_list_init(&output->cursors);
wl_list_init(&output->wl_resources);
wl_signal_init(&output->events.frame); wl_signal_init(&output->events.frame);
wl_signal_init(&output->events.swap_buffers); wl_signal_init(&output->events.swap_buffers);
wl_signal_init(&output->events.resolution); wl_signal_init(&output->events.resolution);
@ -251,15 +274,60 @@ void wlr_output_make_current(struct wlr_output *output) {
output->impl->make_current(output); output->impl->make_current(output);
} }
static void output_fullscreen_surface_render(struct wlr_output *output,
struct wlr_surface *surface, const struct timespec *when) {
int width, height;
wlr_output_effective_resolution(output, &width, &height);
int x = (width - surface->current->width) / 2;
int y = (height - surface->current->height) / 2;
int render_x = x * output->scale;
int render_y = y * output->scale;
int render_width = surface->current->width * output->scale;
int render_height = surface->current->height * output->scale;
glViewport(0, 0, output->width, output->height);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
if (!wlr_surface_has_buffer(surface)) {
return;
}
float translate[16];
wlr_matrix_translate(&translate, render_x, render_y, 0);
float scale[16];
wlr_matrix_scale(&scale, render_width, render_height, 1);
float matrix[16];
wlr_matrix_mul(&translate, &scale, &matrix);
wlr_matrix_mul(&output->transform_matrix, &matrix, &matrix);
wlr_render_with_matrix(surface->renderer, surface->texture, &matrix);
wlr_surface_send_frame_done(surface, when);
}
/**
* Returns the cursor box, scaled for its output.
*/
static void output_cursor_get_box(struct wlr_output_cursor *cursor, static void output_cursor_get_box(struct wlr_output_cursor *cursor,
struct wlr_box *box) { struct wlr_box *box) {
box->x = cursor->x - cursor->hotspot_x; box->x = cursor->x - cursor->hotspot_x;
box->y = cursor->y - cursor->hotspot_y; box->y = cursor->y - cursor->hotspot_y;
box->width = cursor->width; box->width = cursor->width;
box->height = cursor->height; box->height = cursor->height;
if (cursor->surface != NULL) {
box->x += cursor->surface->current->sx * cursor->output->scale;
box->y += cursor->surface->current->sy * cursor->output->scale;
}
} }
static void output_cursor_render(struct wlr_output_cursor *cursor) { static void output_cursor_render(struct wlr_output_cursor *cursor,
const struct timespec *when) {
struct wlr_texture *texture = cursor->texture; struct wlr_texture *texture = cursor->texture;
struct wlr_renderer *renderer = cursor->renderer; struct wlr_renderer *renderer = cursor->renderer;
if (cursor->surface != NULL) { if (cursor->surface != NULL) {
@ -271,48 +339,48 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) {
return; return;
} }
struct wlr_box output_box;
output_box.x = output_box.y = 0;
wlr_output_effective_resolution(cursor->output, &output_box.width,
&output_box.height);
output_box.width *= cursor->output->scale;
output_box.height *= cursor->output->scale;
struct wlr_box cursor_box;
output_cursor_get_box(cursor, &cursor_box);
struct wlr_box intersection;
struct wlr_box *intersection_ptr = &intersection;
if (!wlr_box_intersection(&output_box, &cursor_box, &intersection_ptr)) {
return;
}
glViewport(0, 0, cursor->output->width, cursor->output->height); glViewport(0, 0, cursor->output->width, cursor->output->height);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
int x = cursor->x - cursor->hotspot_x; struct wlr_box cursor_box;
int y = cursor->y - cursor->hotspot_y; output_cursor_get_box(cursor, &cursor_box);
if (cursor->surface != NULL) {
x += cursor->surface->current->sx; float translate[16];
y += cursor->surface->current->sy; wlr_matrix_translate(&translate, cursor_box.x, cursor_box.y, 0);
}
float scale[16];
wlr_matrix_scale(&scale, cursor_box.width, cursor_box.height, 1);
float matrix[16]; float matrix[16];
wlr_texture_get_matrix(texture, &matrix, &cursor->output->transform_matrix, wlr_matrix_mul(&translate, &scale, &matrix);
x, y); wlr_matrix_mul(&cursor->output->transform_matrix, &matrix, &matrix);
wlr_render_with_matrix(renderer, texture, &matrix); wlr_render_with_matrix(renderer, texture, &matrix);
if (cursor->surface != NULL) {
wlr_surface_send_frame_done(cursor->surface, when);
}
} }
void wlr_output_swap_buffers(struct wlr_output *output) { void wlr_output_swap_buffers(struct wlr_output *output) {
wl_signal_emit(&output->events.swap_buffers, &output); wl_signal_emit(&output->events.swap_buffers, &output);
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
if (output->fullscreen_surface != NULL) {
output_fullscreen_surface_render(output, output->fullscreen_surface,
&now);
}
struct wlr_output_cursor *cursor; struct wlr_output_cursor *cursor;
wl_list_for_each(cursor, &output->cursors, link) { wl_list_for_each(cursor, &output->cursors, link) {
if (!cursor->enabled || output->hardware_cursor == cursor) { if (!cursor->enabled || !cursor->visible ||
output->hardware_cursor == cursor) {
continue; continue;
} }
output_cursor_render(cursor); output_cursor_render(cursor, &now);
} }
output->impl->swap_buffers(output); output->impl->swap_buffers(output);
@ -333,6 +401,56 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) {
return output->impl->get_gamma_size(output); return output->impl->get_gamma_size(output);
} }
static void output_fullscreen_surface_reset(struct wlr_output *output) {
if (output->fullscreen_surface != NULL) {
wl_list_remove(&output->fullscreen_surface_commit.link);
wl_list_remove(&output->fullscreen_surface_destroy.link);
output->fullscreen_surface = NULL;
output->needs_swap = true;
}
}
static void output_fullscreen_surface_handle_commit(
struct wl_listener *listener, void *data) {
struct wlr_output *output = wl_container_of(listener, output,
fullscreen_surface_commit);
output->needs_swap = true;
}
static void output_fullscreen_surface_handle_destroy(
struct wl_listener *listener, void *data) {
struct wlr_output *output = wl_container_of(listener, output,
fullscreen_surface_destroy);
output_fullscreen_surface_reset(output);
}
void wlr_output_set_fullscreen_surface(struct wlr_output *output,
struct wlr_surface *surface) {
// TODO: hardware fullscreen
if (output->fullscreen_surface == surface) {
return;
}
output_fullscreen_surface_reset(output);
output->fullscreen_surface = surface;
output->needs_swap = true;
if (surface == NULL) {
return;
}
output->fullscreen_surface_commit.notify =
output_fullscreen_surface_handle_commit;
wl_signal_add(&surface->events.commit, &output->fullscreen_surface_commit);
output->fullscreen_surface_destroy.notify =
output_fullscreen_surface_handle_destroy;
wl_signal_add(&surface->events.destroy,
&output->fullscreen_surface_destroy);
}
static void output_cursor_reset(struct wlr_output_cursor *cursor) { static void output_cursor_reset(struct wlr_output_cursor *cursor) {
if (cursor->output->hardware_cursor != cursor) { if (cursor->output->hardware_cursor != cursor) {
cursor->output->needs_swap = true; cursor->output->needs_swap = true;
@ -356,6 +474,10 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
if (cursor->output->hardware_cursor == NULL && if (cursor->output->hardware_cursor == NULL &&
cursor->output->impl->set_cursor) { cursor->output->impl->set_cursor) {
if (cursor->output->impl->move_cursor) {
cursor->output->impl->move_cursor(cursor->output,
(int)cursor->x, (int)cursor->y);
}
int ok = cursor->output->impl->set_cursor(cursor->output, pixels, int ok = cursor->output->impl->set_cursor(cursor->output, pixels,
stride, width, height, hotspot_x, hotspot_y, true); stride, width, height, hotspot_x, hotspot_y, true);
if (ok) { if (ok) {
@ -390,40 +512,56 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
stride, width, height, pixels); stride, width, height, pixels);
} }
static void output_cursor_update_visible(struct wlr_output_cursor *cursor) {
struct wlr_box output_box;
output_box.x = output_box.y = 0;
wlr_output_effective_resolution(cursor->output, &output_box.width,
&output_box.height);
output_box.width *= cursor->output->scale;
output_box.height *= cursor->output->scale;
struct wlr_box cursor_box;
output_cursor_get_box(cursor, &cursor_box);
struct wlr_box intersection;
struct wlr_box *intersection_ptr = &intersection;
bool visible =
wlr_box_intersection(&output_box, &cursor_box, &intersection_ptr);
if (cursor->surface != NULL) {
if (cursor->visible && !visible) {
wlr_surface_send_leave(cursor->surface, cursor->output);
}
if (!cursor->visible && visible) {
wlr_surface_send_enter(cursor->surface, cursor->output);
}
}
cursor->visible = visible;
}
static void output_cursor_commit(struct wlr_output_cursor *cursor) { static void output_cursor_commit(struct wlr_output_cursor *cursor) {
// Some clients commit a cursor surface with a NULL buffer to hide it. // Some clients commit a cursor surface with a NULL buffer to hide it.
cursor->enabled = wlr_surface_has_buffer(cursor->surface); cursor->enabled = wlr_surface_has_buffer(cursor->surface);
cursor->width = cursor->surface->current->width; cursor->width = cursor->surface->current->width * cursor->output->scale;
cursor->height = cursor->surface->current->height; cursor->height = cursor->surface->current->height * cursor->output->scale;
if (cursor->output->hardware_cursor != cursor) { if (cursor->output->hardware_cursor != cursor) {
cursor->output->needs_swap = true; cursor->output->needs_swap = true;
} else { } else {
// TODO: upload pixels // TODO: upload pixels
}
}
static inline int64_t timespec_to_msec(const struct timespec *a) { struct timespec now;
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; clock_gettime(CLOCK_MONOTONIC, &now);
wlr_surface_send_frame_done(cursor->surface, &now);
}
} }
static void output_cursor_handle_commit(struct wl_listener *listener, static void output_cursor_handle_commit(struct wl_listener *listener,
void *data) { void *data) {
struct wlr_output_cursor *cursor = wl_container_of(listener, cursor, struct wlr_output_cursor *cursor = wl_container_of(listener, cursor,
surface_commit); surface_commit);
struct wlr_surface *surface = data;
output_cursor_commit(cursor); output_cursor_commit(cursor);
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
struct wlr_frame_callback *cb, *cnext;
wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list,
link) {
wl_callback_send_done(cb->resource, timespec_to_msec(&now));
wl_resource_destroy(cb->resource);
}
} }
static void output_cursor_handle_destroy(struct wl_listener *listener, static void output_cursor_handle_destroy(struct wl_listener *listener,
@ -439,8 +577,8 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor,
return; return;
} }
cursor->hotspot_x = hotspot_x; cursor->hotspot_x = hotspot_x * cursor->output->scale;
cursor->hotspot_y = hotspot_y; cursor->hotspot_y = hotspot_y * cursor->output->scale;
if (surface && surface == cursor->surface) { if (surface && surface == cursor->surface) {
if (cursor->output->hardware_cursor == cursor && if (cursor->output->hardware_cursor == cursor &&
@ -470,6 +608,9 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor,
wl_signal_add(&surface->events.commit, &cursor->surface_commit); wl_signal_add(&surface->events.commit, &cursor->surface_commit);
wl_signal_add(&surface->events.destroy, &cursor->surface_destroy); wl_signal_add(&surface->events.destroy, &cursor->surface_destroy);
output_cursor_commit(cursor); output_cursor_commit(cursor);
cursor->visible = false;
output_cursor_update_visible(cursor);
} else { } else {
cursor->enabled = false; cursor->enabled = false;
cursor->width = 0; cursor->width = 0;
@ -485,6 +626,7 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor,
y *= cursor->output->scale; y *= cursor->output->scale;
cursor->x = x; cursor->x = x;
cursor->y = y; cursor->y = y;
output_cursor_update_visible(cursor);
if (cursor->output->hardware_cursor != cursor) { if (cursor->output->hardware_cursor != cursor) {
cursor->output->needs_swap = true; cursor->output->needs_swap = true;

View File

@ -929,3 +929,17 @@ void wlr_surface_send_leave(struct wlr_surface *surface,
} }
} }
} }
static inline int64_t timespec_to_msec(const struct timespec *a) {
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
}
void wlr_surface_send_frame_done(struct wlr_surface *surface,
const struct timespec *when) {
struct wlr_frame_callback *cb, *cnext;
wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list,
link) {
wl_callback_send_done(cb->resource, timespec_to_msec(when));
wl_resource_destroy(cb->resource);
}
}

View File

@ -108,25 +108,17 @@ static void shell_surface_protocol_pong(struct wl_client *client,
static void shell_surface_protocol_move(struct wl_client *client, static void shell_surface_protocol_move(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource, struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial) { uint32_t serial) {
wlr_log(L_DEBUG, "got shell surface move");
struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource);
struct wlr_seat_client *seat = struct wlr_seat_client *seat =
wl_resource_get_user_data(seat_resource); wl_resource_get_user_data(seat_resource);
struct wlr_wl_shell_surface_move_event *event = struct wlr_wl_shell_surface_move_event event = {
calloc(1, sizeof(struct wlr_wl_shell_surface_move_event)); .surface = surface,
if (event == NULL) { .seat = seat,
wl_client_post_no_memory(client); .serial = serial,
return; };
}
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
wl_signal_emit(&surface->events.request_move, event); wl_signal_emit(&surface->events.request_move, &event);
free(event);
} }
static struct wlr_wl_shell_popup_grab *shell_popup_grab_from_seat( static struct wlr_wl_shell_popup_grab *shell_popup_grab_from_seat(
@ -174,26 +166,18 @@ static void shell_surface_destroy_popup_state(
static void shell_surface_protocol_resize(struct wl_client *client, static void shell_surface_protocol_resize(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource, struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, enum wl_shell_surface_resize edges) { uint32_t serial, enum wl_shell_surface_resize edges) {
wlr_log(L_DEBUG, "got shell surface resize");
struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource);
struct wlr_seat_client *seat = struct wlr_seat_client *seat =
wl_resource_get_user_data(seat_resource); wl_resource_get_user_data(seat_resource);
struct wlr_wl_shell_surface_resize_event *event = struct wlr_wl_shell_surface_resize_event event = {
calloc(1, sizeof(struct wlr_wl_shell_surface_resize_event)); .surface = surface,
if (event == NULL) { .seat = seat,
wl_client_post_no_memory(client); .serial = serial,
return; .edges = edges,
} };
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
event->edges = edges;
wl_signal_emit(&surface->events.request_resize, event); wl_signal_emit(&surface->events.request_resize, &event);
free(event);
} }
static void shell_surface_set_state(struct wlr_wl_shell_surface *surface, static void shell_surface_set_state(struct wlr_wl_shell_surface *surface,
@ -279,7 +263,6 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
enum wl_shell_surface_fullscreen_method method, uint32_t framerate, enum wl_shell_surface_fullscreen_method method, uint32_t framerate,
struct wl_resource *output_resource) { struct wl_resource *output_resource) {
wlr_log(L_DEBUG, "got shell surface fullscreen");
struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource);
struct wlr_output *output = NULL; struct wlr_output *output = NULL;
if (output_resource != NULL) { if (output_resource != NULL) {
@ -289,23 +272,15 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client,
shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN, shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN,
NULL, NULL); NULL, NULL);
struct wlr_wl_shell_surface_set_fullscreen_event *event = struct wlr_wl_shell_surface_set_fullscreen_event event = {
calloc(1, sizeof(struct wlr_wl_shell_surface_set_fullscreen_event)); .surface = surface,
if (event == NULL) { .method = method,
wl_client_post_no_memory(client); .framerate = framerate,
return; .output = output,
};
wl_signal_emit(&surface->events.request_fullscreen, &event);
} }
event->client = client;
event->surface = surface;
event->method = method;
event->framerate = framerate;
event->output = output;
wl_signal_emit(&surface->events.request_set_fullscreen, event);
free(event);
}
static void shell_surface_protocol_set_popup(struct wl_client *client, static void shell_surface_protocol_set_popup(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource, struct wl_resource *resource, struct wl_resource *seat_resource,
@ -368,7 +343,6 @@ static void shell_surface_protocol_set_popup(struct wl_client *client,
static void shell_surface_protocol_set_maximized(struct wl_client *client, static void shell_surface_protocol_set_maximized(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *output_resource) { struct wl_resource *resource, struct wl_resource *output_resource) {
wlr_log(L_DEBUG, "got shell surface maximized");
struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource);
struct wlr_output *output = NULL; struct wlr_output *output = NULL;
if (output_resource != NULL) { if (output_resource != NULL) {
@ -378,19 +352,12 @@ static void shell_surface_protocol_set_maximized(struct wl_client *client,
shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED, shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED,
NULL, NULL); NULL, NULL);
struct wlr_wl_shell_surface_set_maximized_event *event = struct wlr_wl_shell_surface_maximize_event event = {
calloc(1, sizeof(struct wlr_wl_shell_surface_set_maximized_event)); .surface = surface,
if (event == NULL) { .output = output,
wl_client_post_no_memory(client); };
return;
}
event->client = client;
event->surface = surface;
event->output = output;
wl_signal_emit(&surface->events.request_set_maximized, event); wl_signal_emit(&surface->events.request_maximize, &event);
free(event);
} }
static void shell_surface_protocol_set_title(struct wl_client *client, static void shell_surface_protocol_set_title(struct wl_client *client,
@ -492,6 +459,8 @@ static void handle_wlr_surface_committed(struct wl_listener *listener,
surface->popup_state->seat); surface->popup_state->seat);
shell_pointer_grab_maybe_end(&grab->pointer_grab); shell_pointer_grab_maybe_end(&grab->pointer_grab);
} }
wl_signal_emit(&surface->events.commit, surface);
} }
static int shell_surface_ping_timeout(void *user_data) { static int shell_surface_ping_timeout(void *user_data) {
@ -542,11 +511,12 @@ static void shell_protocol_get_shell_surface(struct wl_client *client,
wl_surface->resource); wl_surface->resource);
wl_signal_init(&wl_surface->events.destroy); wl_signal_init(&wl_surface->events.destroy);
wl_signal_init(&wl_surface->events.commit);
wl_signal_init(&wl_surface->events.ping_timeout); wl_signal_init(&wl_surface->events.ping_timeout);
wl_signal_init(&wl_surface->events.request_move); wl_signal_init(&wl_surface->events.request_move);
wl_signal_init(&wl_surface->events.request_resize); wl_signal_init(&wl_surface->events.request_resize);
wl_signal_init(&wl_surface->events.request_set_fullscreen); wl_signal_init(&wl_surface->events.request_fullscreen);
wl_signal_init(&wl_surface->events.request_set_maximized); wl_signal_init(&wl_surface->events.request_maximize);
wl_signal_init(&wl_surface->events.set_state); wl_signal_init(&wl_surface->events.set_state);
wl_signal_init(&wl_surface->events.set_title); wl_signal_init(&wl_surface->events.set_title);
wl_signal_init(&wl_surface->events.set_class); wl_signal_init(&wl_surface->events.set_class);

View File

@ -564,23 +564,15 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client,
return; return;
} }
struct wlr_xdg_toplevel_v6_show_window_menu_event *event = struct wlr_xdg_toplevel_v6_show_window_menu_event event = {
calloc(1, sizeof(struct wlr_xdg_toplevel_v6_show_window_menu_event)); .surface = surface,
if (event == NULL) { .seat = seat,
wl_client_post_no_memory(client); .serial = serial,
return; .x = x,
} .y = y,
};
event->client = client; wl_signal_emit(&surface->events.request_show_window_menu, &event);
event->surface = surface;
event->seat = seat;
event->serial = serial;
event->x = x;
event->y = y;
wl_signal_emit(&surface->events.request_show_window_menu, event);
free(event);
} }
static void xdg_toplevel_protocol_move(struct wl_client *client, static void xdg_toplevel_protocol_move(struct wl_client *client,
@ -597,21 +589,13 @@ static void xdg_toplevel_protocol_move(struct wl_client *client,
return; return;
} }
struct wlr_xdg_toplevel_v6_move_event *event = struct wlr_xdg_toplevel_v6_move_event event = {
calloc(1, sizeof(struct wlr_xdg_toplevel_v6_move_event)); .surface = surface,
if (event == NULL) { .seat = seat,
wl_client_post_no_memory(client); .serial = serial,
return; };
}
event->client = client; wl_signal_emit(&surface->events.request_move, &event);
event->surface = surface;
event->seat = seat;
event->serial = serial;
wl_signal_emit(&surface->events.request_move, event);
free(event);
} }
static void xdg_toplevel_protocol_resize(struct wl_client *client, static void xdg_toplevel_protocol_resize(struct wl_client *client,
@ -628,22 +612,14 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client,
return; return;
} }
struct wlr_xdg_toplevel_v6_resize_event *event = struct wlr_xdg_toplevel_v6_resize_event event = {
calloc(1, sizeof(struct wlr_xdg_toplevel_v6_resize_event)); .surface = surface,
if (event == NULL) { .seat = seat,
wl_client_post_no_memory(client); .serial = serial,
return; .edges = edges,
} };
event->client = client; wl_signal_emit(&surface->events.request_resize, &event);
event->surface = surface;
event->seat = seat;
event->serial = serial;
event->edges = edges;
wl_signal_emit(&surface->events.request_resize, event);
free(event);
} }
static void xdg_toplevel_protocol_set_max_size(struct wl_client *client, static void xdg_toplevel_protocol_set_max_size(struct wl_client *client,
@ -677,15 +653,36 @@ static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client,
static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *output_resource) { struct wl_resource *resource, struct wl_resource *output_resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
struct wlr_output *output = NULL;
if (output_resource != NULL) {
output = wl_resource_get_user_data(output_resource);
}
surface->toplevel_state->next.fullscreen = true; surface->toplevel_state->next.fullscreen = true;
wl_signal_emit(&surface->events.request_fullscreen, surface);
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
.surface = surface,
.fullscreen = true,
.output = output,
};
wl_signal_emit(&surface->events.request_fullscreen, &event);
} }
static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client,
struct wl_resource *resource) { struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
surface->toplevel_state->next.fullscreen = false; surface->toplevel_state->next.fullscreen = false;
wl_signal_emit(&surface->events.request_fullscreen, surface);
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
.surface = surface,
.fullscreen = false,
.output = NULL,
};
wl_signal_emit(&surface->events.request_fullscreen, &event);
} }
static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, static void xdg_toplevel_protocol_set_minimized(struct wl_client *client,
@ -812,8 +809,7 @@ static void xdg_surface_ack_configure(struct wl_client *client,
} }
surface->configured = true; surface->configured = true;
surface->configure_serial = serial;
wl_signal_emit(&surface->events.ack_configure, surface);
free(configure); free(configure);
} }
@ -941,7 +937,6 @@ static void wlr_xdg_toplevel_v6_send_configure(
static void wlr_xdg_surface_send_configure(void *user_data) { static void wlr_xdg_surface_send_configure(void *user_data) {
struct wlr_xdg_surface_v6 *surface = user_data; struct wlr_xdg_surface_v6 *surface = user_data;
struct wl_display *display = wl_client_get_display(surface->client->client);
surface->configure_idle = NULL; surface->configure_idle = NULL;
@ -953,7 +948,7 @@ static void wlr_xdg_surface_send_configure(void *user_data) {
} }
wl_list_insert(surface->configure_list.prev, &configure->link); wl_list_insert(surface->configure_list.prev, &configure->link);
configure->serial = wl_display_next_serial(display); configure->serial = surface->configure_next_serial;
switch (surface->role) { switch (surface->role) {
case WLR_XDG_SURFACE_V6_ROLE_NONE: case WLR_XDG_SURFACE_V6_ROLE_NONE:
@ -974,7 +969,7 @@ static void wlr_xdg_surface_send_configure(void *user_data) {
zxdg_surface_v6_send_configure(surface->resource, configure->serial); zxdg_surface_v6_send_configure(surface->resource, configure->serial);
} }
static void wlr_xdg_surface_v6_schedule_configure( static uint32_t wlr_xdg_surface_v6_schedule_configure(
struct wlr_xdg_surface_v6 *surface) { struct wlr_xdg_surface_v6 *surface) {
struct wl_display *display = wl_client_get_display(surface->client->client); struct wl_display *display = wl_client_get_display(surface->client->client);
struct wl_event_loop *loop = wl_display_get_event_loop(display); struct wl_event_loop *loop = wl_display_get_event_loop(display);
@ -995,23 +990,23 @@ static void wlr_xdg_surface_v6_schedule_configure(
if (surface->configure_idle != NULL) { if (surface->configure_idle != NULL) {
if (!pending_same) { if (!pending_same) {
// configure request already scheduled // configure request already scheduled
return; return surface->configure_next_serial;
} }
// configure request not necessary anymore // configure request not necessary anymore
wl_event_source_remove(surface->configure_idle); wl_event_source_remove(surface->configure_idle);
surface->configure_idle = NULL; surface->configure_idle = NULL;
return 0;
} else { } else {
if (pending_same) { if (pending_same) {
// configure request not necessary // configure request not necessary
return; return 0;
} }
surface->configure_idle = surface->configure_next_serial = wl_display_next_serial(display);
wl_event_loop_add_idle( surface->configure_idle = wl_event_loop_add_idle(loop,
loop, wlr_xdg_surface_send_configure, surface);
wlr_xdg_surface_send_configure, return surface->configure_next_serial;
surface);
} }
} }
@ -1155,7 +1150,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
wl_signal_init(&surface->events.request_show_window_menu); wl_signal_init(&surface->events.request_show_window_menu);
wl_signal_init(&surface->events.commit); wl_signal_init(&surface->events.commit);
wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.ack_configure);
wl_signal_init(&surface->events.ping_timeout); wl_signal_init(&surface->events.ping_timeout);
wl_signal_add(&surface->surface->events.destroy, wl_signal_add(&surface->surface->events.destroy,
@ -1304,45 +1298,45 @@ void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface) {
surface->client->ping_serial); surface->client->ping_serial);
} }
void wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface,
uint32_t width, uint32_t height) { uint32_t width, uint32_t height) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
surface->toplevel_state->pending.width = width; surface->toplevel_state->pending.width = width;
surface->toplevel_state->pending.height = height; surface->toplevel_state->pending.height = height;
wlr_xdg_surface_v6_schedule_configure(surface); return wlr_xdg_surface_v6_schedule_configure(surface);
} }
void wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface,
bool activated) { bool activated) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
surface->toplevel_state->pending.activated = activated; surface->toplevel_state->pending.activated = activated;
wlr_xdg_surface_v6_schedule_configure(surface); return wlr_xdg_surface_v6_schedule_configure(surface);
} }
void wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface,
bool maximized) { bool maximized) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
surface->toplevel_state->pending.maximized = maximized; surface->toplevel_state->pending.maximized = maximized;
wlr_xdg_surface_v6_schedule_configure(surface); return wlr_xdg_surface_v6_schedule_configure(surface);
} }
void wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface,
bool fullscreen) { bool fullscreen) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
surface->toplevel_state->pending.fullscreen = fullscreen; surface->toplevel_state->pending.fullscreen = fullscreen;
wlr_xdg_surface_v6_schedule_configure(surface); return wlr_xdg_surface_v6_schedule_configure(surface);
} }
void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface,
bool resizing) { bool resizing) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
surface->toplevel_state->pending.resizing = resizing; surface->toplevel_state->pending.resizing = resizing;
wlr_xdg_surface_v6_schedule_configure(surface); return wlr_xdg_surface_v6_schedule_configure(surface);
} }
void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) { void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) {

View File

@ -2,6 +2,7 @@ lib_wlr_util = static_library(
'wlr_util', 'wlr_util',
files( files(
'log.c', 'log.c',
'os-compatibility.c',
), ),
include_directories: wlr_inc, include_directories: wlr_inc,
) )

View File

@ -29,15 +29,11 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#ifdef __linux__
#include <sys/epoll.h>
#endif
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "util/os-compatibility.h"
int int os_fd_set_cloexec(int fd) {
os_fd_set_cloexec(int fd)
{
long flags; long flags;
if (fd == -1) if (fd == -1)
@ -53,9 +49,7 @@ os_fd_set_cloexec(int fd)
return 0; return 0;
} }
static int int set_cloexec_or_close(int fd) {
set_cloexec_or_close(int fd)
{
if (os_fd_set_cloexec(fd) != 0) { if (os_fd_set_cloexec(fd) != 0) {
close(fd); close(fd);
return -1; return -1;
@ -63,8 +57,7 @@ set_cloexec_or_close(int fd)
return fd; return fd;
} }
static int int create_tmpfile_cloexec(char *tmpname)
create_tmpfile_cloexec(char *tmpname)
{ {
int fd; int fd;
@ -104,9 +97,7 @@ create_tmpfile_cloexec(char *tmpname)
* If posix_fallocate() is not supported, program may receive * If posix_fallocate() is not supported, program may receive
* SIGBUS on accessing mmap()'ed file contents instead. * SIGBUS on accessing mmap()'ed file contents instead.
*/ */
int int os_create_anonymous_file(off_t size) {
os_create_anonymous_file(off_t size)
{
static const char template[] = "/wlroots-shared-XXXXXX"; static const char template[] = "/wlroots-shared-XXXXXX";
const char *path; const char *path;
char *name; char *name;

View File

@ -326,3 +326,26 @@ static int wlr_xcursor_frame_and_duration(struct wlr_xcursor *cursor,
int wlr_xcursor_frame(struct wlr_xcursor *_cursor, uint32_t time) { int wlr_xcursor_frame(struct wlr_xcursor *_cursor, uint32_t time) {
return wlr_xcursor_frame_and_duration(_cursor, time, NULL); return wlr_xcursor_frame_and_duration(_cursor, time, NULL);
} }
const char *wlr_xcursor_get_resize_name(enum wlr_edges edges) {
if (edges & WLR_EDGE_TOP) {
if (edges & WLR_EDGE_RIGHT) {
return "ne-resize";
} else if (edges & WLR_EDGE_LEFT) {
return "nw-resize";
}
return "n-resize";
} else if (edges & WLR_EDGE_BOTTOM) {
if (edges & WLR_EDGE_RIGHT) {
return "se-resize";
} else if (edges & WLR_EDGE_LEFT) {
return "sw-resize";
}
return "s-resize";
} else if (edges & WLR_EDGE_RIGHT) {
return "e-resize";
} else if (edges & WLR_EDGE_LEFT) {
return "w-resize";
}
return "se-resize"; // fallback
}

View File

@ -21,6 +21,9 @@
static const char *lock_fmt = "/tmp/.X%d-lock"; static const char *lock_fmt = "/tmp/.X%d-lock";
static const char *socket_dir = "/tmp/.X11-unix"; static const char *socket_dir = "/tmp/.X11-unix";
static const char *socket_fmt = "/tmp/.X11-unix/X%d"; static const char *socket_fmt = "/tmp/.X11-unix/X%d";
#ifndef __linux__
static const char *socket_fmt2 = "/tmp/.X11-unix/X%d_";
#endif
static int open_socket(struct sockaddr_un *addr, size_t path_size) { static int open_socket(struct sockaddr_un *addr, size_t path_size) {
int fd, rc; int fd, rc;
@ -73,7 +76,7 @@ static bool open_sockets(int socks[2], int display) {
addr.sun_path[0] = 0; addr.sun_path[0] = 0;
path_size = snprintf(addr.sun_path + 1, sizeof(addr.sun_path) - 1, socket_fmt, display); path_size = snprintf(addr.sun_path + 1, sizeof(addr.sun_path) - 1, socket_fmt, display);
#else #else
path_size = snprintf(addr.sun_path, sizeof(addr.sun_path), socket_fmt, display); path_size = snprintf(addr.sun_path, sizeof(addr.sun_path), socket_fmt2, display);
#endif #endif
socks[0] = open_socket(&addr, path_size); socks[0] = open_socket(&addr, path_size);
if (socks[0] < 0) { if (socks[0] < 0) {
@ -97,6 +100,11 @@ void unlink_display_sockets(int display) {
snprintf(sun_path, sizeof(sun_path), socket_fmt, display); snprintf(sun_path, sizeof(sun_path), socket_fmt, display);
unlink(sun_path); unlink(sun_path);
#ifndef __linux__
snprintf(sun_path, sizeof(sun_path), socket_fmt2, display);
unlink(sun_path);
#endif
snprintf(sun_path, sizeof(sun_path), lock_fmt, display); snprintf(sun_path, sizeof(sun_path), lock_fmt, display);
unlink(sun_path); unlink(sun_path);
} }

View File

@ -8,6 +8,7 @@
#include <xcb/xcb_image.h> #include <xcb/xcb_image.h>
#include <xcb/render.h> #include <xcb/render.h>
#include "wlr/util/log.h" #include "wlr/util/log.h"
#include "wlr/util/edges.h"
#include "wlr/types/wlr_surface.h" #include "wlr/types/wlr_surface.h"
#include "wlr/xwayland.h" #include "wlr/xwayland.h"
#include "wlr/xcursor.h" #include "wlr/xcursor.h"
@ -598,7 +599,7 @@ static void xwm_handle_configure_request(struct wlr_xwm *xwm,
if (xsurface->surface == NULL) { if (xsurface->surface == NULL) {
// Surface has not been mapped yet // Surface has not been mapped yet
wlr_xwayland_surface_configure(xwm->xwayland, xsurface, ev->x, ev->y, wlr_xwayland_surface_configure(xsurface, ev->x, ev->y,
ev->width, ev->height); ev->width, ev->height);
} else { } else {
struct wlr_xwayland_surface_configure_event *wlr_event = struct wlr_xwayland_surface_configure_event *wlr_event =
@ -750,14 +751,43 @@ static void xwm_handle_surface_id_message(struct wlr_xwm *xwm,
#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 // move via keyboard #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 // move via keyboard
#define _NET_WM_MOVERESIZE_CANCEL 11 // cancel operation #define _NET_WM_MOVERESIZE_CANCEL 11 // cancel operation
static enum wlr_edges net_wm_edges_to_wlr(uint32_t net_wm_edges) {
enum wlr_edges edges = WLR_EDGE_NONE;
switch(net_wm_edges) {
case _NET_WM_MOVERESIZE_SIZE_TOPLEFT:
edges = WLR_EDGE_TOP | WLR_EDGE_LEFT;
break;
case _NET_WM_MOVERESIZE_SIZE_TOP:
edges = WLR_EDGE_TOP;
break;
case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT:
edges = WLR_EDGE_TOP | WLR_EDGE_RIGHT;
break;
case _NET_WM_MOVERESIZE_SIZE_RIGHT:
edges = WLR_EDGE_RIGHT;
break;
case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT:
edges = WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT;
break;
case _NET_WM_MOVERESIZE_SIZE_BOTTOM:
edges = WLR_EDGE_BOTTOM;
break;
case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT:
edges = WLR_EDGE_BOTTOM | WLR_EDGE_LEFT;
break;
case _NET_WM_MOVERESIZE_SIZE_LEFT:
edges = WLR_EDGE_LEFT;
break;
default:
break;
}
return edges;
}
static void xwm_handle_net_wm_moveresize_message(struct wlr_xwm *xwm, static void xwm_handle_net_wm_moveresize_message(struct wlr_xwm *xwm,
xcb_client_message_event_t *ev) { xcb_client_message_event_t *ev) {
// same as xdg-toplevel-v6
// TODO need a common enum for this
static const int map[] = {
5, 1, 9, 8, 10, 2, 6, 4
};
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
if (!xsurface) { if (!xsurface) {
return; return;
@ -783,7 +813,7 @@ static void xwm_handle_net_wm_moveresize_message(struct wlr_xwm *xwm,
case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT: case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT:
case _NET_WM_MOVERESIZE_SIZE_LEFT: case _NET_WM_MOVERESIZE_SIZE_LEFT:
resize_event.surface = xsurface; resize_event.surface = xsurface;
resize_event.edges = map[detail]; resize_event.edges = net_wm_edges_to_wlr(detail);
wl_signal_emit(&xsurface->events.request_resize, &resize_event); wl_signal_emit(&xsurface->events.request_resize, &resize_event);
break; break;
case _NET_WM_MOVERESIZE_CANCEL: case _NET_WM_MOVERESIZE_CANCEL:
@ -995,25 +1025,24 @@ static void handle_compositor_surface_create(struct wl_listener *listener,
} }
} }
void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_activate(struct wlr_xwayland_surface *xsurface,
struct wlr_xwayland_surface *xsurface, bool activated) { bool activated) {
struct wlr_xwayland_surface *focused = wlr_xwayland->xwm->focus_surface; struct wlr_xwayland_surface *focused = xsurface->xwm->focus_surface;
if (activated) { if (activated) {
xwm_surface_activate(wlr_xwayland->xwm, xsurface); xwm_surface_activate(xsurface->xwm, xsurface);
} else if (focused == xsurface) { } else if (focused == xsurface) {
xwm_surface_activate(wlr_xwayland->xwm, NULL); xwm_surface_activate(xsurface->xwm, NULL);
} }
} }
void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_configure(struct wlr_xwayland_surface *xsurface,
struct wlr_xwayland_surface *xsurface, int16_t x, int16_t y, int16_t x, int16_t y, uint16_t width, uint16_t height) {
uint16_t width, uint16_t height) {
xsurface->x = x; xsurface->x = x;
xsurface->y = y; xsurface->y = y;
xsurface->width = width; xsurface->width = width;
xsurface->height = height; xsurface->height = height;
struct wlr_xwm *xwm = wlr_xwayland->xwm; struct wlr_xwm *xwm = xsurface->xwm;
uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
XCB_CONFIG_WINDOW_BORDER_WIDTH; XCB_CONFIG_WINDOW_BORDER_WIDTH;
@ -1022,9 +1051,8 @@ void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland,
xcb_flush(xwm->xcb_conn); xcb_flush(xwm->xcb_conn);
} }
void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_close(struct wlr_xwayland_surface *xsurface) {
struct wlr_xwayland_surface *xsurface) { struct wlr_xwm *xwm = xsurface->xwm;
struct wlr_xwm *xwm = wlr_xwayland->xwm;
bool supports_delete = false; bool supports_delete = false;
for (size_t i = 0; i < xsurface->protocols_len; i++) { for (size_t i = 0; i < xsurface->protocols_len; i++) {
@ -1359,19 +1387,17 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {
return xwm; return xwm;
} }
void wlr_xwayland_surface_set_maximized(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_set_maximized(struct wlr_xwayland_surface *surface,
struct wlr_xwayland_surface *surface, bool maximized) { bool maximized) {
if (xsurface_is_maximized(surface) != maximized) {
surface->maximized_horz = maximized; surface->maximized_horz = maximized;
surface->maximized_vert = maximized; surface->maximized_vert = maximized;
xsurface_set_net_wm_state(surface); xsurface_set_net_wm_state(surface);
} xcb_flush(surface->xwm->xcb_conn);
} }
void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland_surface *surface,
struct wlr_xwayland_surface *surface, bool fullscreen) { bool fullscreen) {
if (surface->fullscreen != fullscreen) {
surface->fullscreen = fullscreen; surface->fullscreen = fullscreen;
xsurface_set_net_wm_state(surface); xsurface_set_net_wm_state(surface);
} xcb_flush(surface->xwm->xcb_conn);
} }