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;
wlr_output_transform_apply_to_box(transform, &box, &transformed_box);
transformed_box.x -= plane->cursor_hotspot_x;
transformed_box.y -= plane->cursor_hotspot_y;
if (plane != NULL) {
transformed_box.x -= plane->cursor_hotspot_x;
transformed_box.y -= plane->cursor_hotspot_y;
}
return drm->iface->crtc_move_cursor(drm, conn->crtc, transformed_box.x,
transformed_box.y);

View file

@ -14,7 +14,7 @@
#include <wlr/render/gles2.h>
#include <wlr/render.h>
#include "backend/drm/drm.h"
#include "render/glapi.h"
#include "glapi.h"
bool wlr_drm_renderer_init(struct wlr_drm_backend *drm,
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];
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_height = ((data[68] & 0x0f) << 8) | data[67];

View file

@ -21,7 +21,6 @@ backend_files = files(
'wayland/output.c',
'wayland/registry.c',
'wayland/wl_seat.c',
'wayland/os-compatibility.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 = {
.mode = VT_PROCESS,
.relsig = SIGUSR1,
.acqsig = SIGUSR1,
.relsig = SIGUSR2,
.acqsig = SIGUSR2,
.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);
session->vt_source = wl_event_loop_add_signal(loop, SIGUSR1,
session->vt_source = wl_event_loop_add_signal(loop, SIGUSR2,
vt_handler, session);
if (!session->vt_source) {
goto error;

View file

@ -184,8 +184,8 @@ static bool setup_tty(struct direct_session *session, struct wl_display *display
struct vt_mode mode = {
.mode = VT_PROCESS,
.relsig = SIGUSR1,
.acqsig = SIGUSR1,
.relsig = SIGUSR2,
.acqsig = SIGUSR2,
};
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);
session->vt_source = wl_event_loop_add_signal(loop, SIGUSR1,
session->vt_source = wl_event_loop_add_signal(loop, SIGUSR2,
vt_handler, session);
if (!session->vt_source) {
goto error;

View file

@ -347,12 +347,6 @@ static struct wlr_session *logind_session_create(struct wl_display *disp) {
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;
ret = sd_session_get_seat(session->id, &seat);
if (ret < 0) {
@ -360,6 +354,14 @@ static struct wlr_session *logind_session_create(struct wl_display *disp) {
goto error;
}
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);
ret = sd_bus_default_system(&session->bus);

View file

@ -29,5 +29,6 @@ executable(
executable(
'screenshot',
'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 <sys/param.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 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
# is NULL before using it.
if [ $# -ne 2 ]; then
if [ $# -ne 3 ]; then
exit 1
fi
SPEC=$1
OUT=$2
OUT_C=$2
OUT_H=$3
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=""
DEFN=""
@ -57,46 +58,37 @@ while read -r COMMAND; do
fi
done < $SPEC
cat > $OUT_H << EOF
#ifndef $INCLUDE_GUARD
#define $INCLUDE_GUARD
case $OUT in
*.h)
cat > $OUT << EOF
#ifndef $INCLUDE_GUARD
#define $INCLUDE_GUARD
#include <stdbool.h>
#include <stdbool.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <EGL/eglmesaext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <EGL/eglmesaext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
bool load_$BASE(void);
$DECL
bool load_$BASE(void);
$DECL
#endif
#endif
EOF
;;
*.c)
cat > $OUT << EOF
#include <wlr/util/log.h>
#include "$BASE.h"
$DEFN
bool load_$BASE(void) {
static bool done = false;
if (done) {
return true;
}
$LOADER
cat > $OUT_C << EOF
#include <wlr/util/log.h>
#include "$OUT_H"
$DEFN
done = true;
return true;
}
bool load_$BASE(void) {
static bool done = false;
if (done) {
return true;
}
$LOADER
done = true;
return true;
}
EOF
;;
*)
exit 1
;;
esac

View file

@ -10,13 +10,6 @@ enum roots_cursor_mode {
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 {
uint32_t serial;
struct wlr_cursor *cursor;

View file

@ -19,13 +19,14 @@ struct roots_output {
struct wlr_output *wlr_output;
struct wl_listener 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 wl_list views; // roots_view::link
struct wl_list outputs;
struct wl_list outputs; // roots_output::link
struct timespec last_frame;
struct roots_server *server;
@ -59,11 +60,13 @@ struct roots_server;
struct roots_desktop *desktop_create(struct roots_server *server,
struct roots_config *config);
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_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 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 request_move;
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 surface_commit;
@ -26,6 +27,9 @@ struct roots_xdg_surface_v6 {
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener request_maximize;
struct wl_listener request_fullscreen;
uint32_t pending_move_resize_configure_serial;
};
struct roots_xwayland_surface {
@ -36,8 +40,11 @@ struct roots_xwayland_surface {
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener request_maximize;
struct wl_listener request_fullscreen;
struct wl_listener map_notify;
struct wl_listener unmap_notify;
struct wl_listener surface_commit;
};
enum roots_view_type {
@ -54,12 +61,19 @@ struct roots_view {
float rotation;
bool maximized;
struct roots_output *fullscreen_output;
struct {
double x, y;
uint32_t width, height;
float rotation;
} saved;
struct {
bool update_x, update_y;
double x, y;
uint32_t width, height;
} pending_move_resize;
// TODO: Something for roots-enforced width/height
enum roots_view_type type;
union {
@ -93,6 +107,7 @@ struct roots_view {
void (*move_resize)(struct roots_view *view, double x, double y,
uint32_t width, uint32_t height);
void (*maximize)(struct roots_view *view, bool maximized);
void (*set_fullscreen)(struct roots_view *view, bool fullscreen);
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,
uint32_t width, uint32_t height);
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);
bool view_center(struct roots_view *view);
void view_setup(struct roots_view *view);

View file

@ -3,12 +3,10 @@
#include <stdint.h>
#define ROOTS_XCURSOR_SIZE 16
#define ROOTS_XCURSOR_SIZE 24
#define ROOTS_XCURSOR_DEFAULT "left_ptr"
#define ROOTS_XCURSOR_MOVE "grabbing"
#define ROOTS_XCURSOR_ROTATE "grabbing"
const char *roots_xcursor_get_resize_name(uint32_t edges);
#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;
double x, y;
bool enabled;
bool visible;
uint32_t width, height;
int32_t hotspot_x, hotspot_y;
struct wl_list link;
@ -64,6 +65,10 @@ struct wlr_output {
struct wl_signal destroy;
} 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 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,
enum wl_output_transform transform);
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_effective_resolution(struct wlr_output *output,
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,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
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);
/**
* Sets the cursor image. The image must be already scaled for the output.
*/
bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height,
int32_t hotspot_x, int32_t hotspot_y);

View file

@ -3,12 +3,35 @@
#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 wl_global *wl_global;
struct wl_list wl_resources;
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 wl_signal new_decoration;
@ -22,7 +45,7 @@ struct wlr_server_decoration {
struct wlr_surface *surface;
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 wl_signal destroy;

View file

@ -1,9 +1,10 @@
#ifndef WLR_TYPES_WLR_SURFACE_H
#define WLR_TYPES_WLR_SURFACE_H
#include <wayland-server.h>
#include <pixman.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <pixman.h>
#include <wayland-server.h>
#include <wlr/types/wlr_output.h>
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,
struct wlr_output *output);
void wlr_surface_send_frame_done(struct wlr_surface *surface,
const struct timespec *when);
#endif

View file

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

View file

@ -107,7 +107,9 @@ struct wlr_xdg_surface_v6 {
bool configured;
bool added;
uint32_t configure_serial;
struct wl_event_source *configure_idle;
uint32_t configure_next_serial;
struct wl_list configure_list;
char *title;
@ -123,7 +125,6 @@ struct wlr_xdg_surface_v6 {
struct {
struct wl_signal commit;
struct wl_signal destroy;
struct wl_signal ack_configure;
struct wl_signal ping_timeout;
struct wl_signal request_maximize;
@ -138,27 +139,29 @@ struct wlr_xdg_surface_v6 {
};
struct wlr_xdg_toplevel_v6_move_event {
struct wl_client *client;
struct wlr_xdg_surface_v6 *surface;
struct wlr_seat_client *seat;
uint32_t serial;
};
struct wlr_xdg_toplevel_v6_resize_event {
struct wl_client *client;
struct wlr_xdg_surface_v6 *surface;
struct wlr_seat_client *seat;
uint32_t serial;
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 wl_client *client;
struct wlr_xdg_surface_v6 *surface;
struct wlr_seat_client *seat;
uint32_t serial;
uint32_t x;
uint32_t y;
uint32_t x, y;
};
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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
@ -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 *surface, double sx, double sy,
double *popup_sx, double *popup_sy);
#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
#include <stdint.h>
#include <wlr/util/edges.h>
struct wlr_xcursor_image {
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);
/**
* Get the name of the resize cursor image for the given edges.
*/
const char *wlr_xcursor_get_resize_name(enum wlr_edges edges);
#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,
int32_t hotspot_x, int32_t hotspot_y);
void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland,
struct wlr_xwayland_surface *surface, bool activated);
void wlr_xwayland_surface_activate(struct wlr_xwayland_surface *surface,
bool activated);
void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland,
struct wlr_xwayland_surface *surface, int16_t x, int16_t y,
uint16_t width, uint16_t height);
void wlr_xwayland_surface_configure(struct wlr_xwayland_surface *surface,
int16_t x, int16_t y, uint16_t width, uint16_t height);
void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland,
struct wlr_xwayland_surface *surface);
void wlr_xwayland_surface_close(struct wlr_xwayland_surface *surface);
void wlr_xwayland_surface_set_maximized(struct wlr_xwayland *wlr_xwayland,
struct wlr_xwayland_surface *surface, bool maximized);
void wlr_xwayland_surface_set_maximized(struct wlr_xwayland_surface *surface,
bool maximized);
void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland *wlr_xwayland,
struct wlr_xwayland_surface *surface, bool fullscreen);
void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland_surface *surface,
bool fullscreen);
void wlr_xwayland_set_seat(struct wlr_xwayland *xwayland,
struct wlr_seat *seat);

View file

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

View file

@ -4,7 +4,7 @@
#include <stdlib.h>
#include <wlr/util/log.h>
#include <wlr/render/egl.h>
#include "render/glapi.h"
#include "glapi.h"
// Extension documentation
// 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/util/log.h>
#include "render/gles2.h"
#include "render/glapi.h"
#include "glapi.h"
struct shaders shaders;

View file

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

View file

@ -120,7 +120,7 @@ void add_binding_config(struct wl_list *bindings, const char* combination,
xkb_keysym_t keysyms[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP];
char *symnames = strdup(combination);
char* symname = strtok(symnames, "+");
char *symname = strtok(symnames, "+");
while (symname) {
uint32_t modifier = parse_modifier(symname);
if (modifier != 0) {
@ -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 wlr_output *output) {
struct roots_output_config *o_config;
wl_list_for_each(o_config, &config->outputs, link) {
if (strcmp(o_config->name, output->name) == 0) {
return o_config;
char name[83];
snprintf(name, sizeof(name), "%s %s %s", output->make, output->model,
output->serial);
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
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h>
#include <wlr/util/edges.h>
#include "rootston/xcursor.h"
#include "rootston/cursor.h"
@ -37,7 +38,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
double sx, sy;
switch (cursor->mode) {
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);
bool set_compositor_cursor = !view && cursor->cursor_client;
if (view) {
@ -71,43 +72,37 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
if (view != NULL) {
double dx = cursor->cursor->x - cursor->offs_x;
double dy = cursor->cursor->y - cursor->offs_y;
double active_x = view->x;
double active_y = view->y;
double x = view->x;
double y = view->y;
int width = cursor->view_width;
int height = cursor->view_height;
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
active_y = cursor->view_y + dy;
if (cursor->resize_edges & WLR_EDGE_TOP) {
y = cursor->view_y + dy;
height -= dy;
if (height < 0) {
active_y += height;
if (height < 1) {
y += height;
}
} else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) {
} else if (cursor->resize_edges & WLR_EDGE_BOTTOM) {
height += dy;
}
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
active_x = cursor->view_x + dx;
if (cursor->resize_edges & WLR_EDGE_LEFT) {
x = cursor->view_x + dx;
width -= dx;
if (width < 0) {
active_x += width;
if (width < 1) {
x += width;
}
} else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
} else if (cursor->resize_edges & WLR_EDGE_RIGHT) {
width += dx;
}
if (width < 0) {
width = 0;
if (width < 1) {
width = 1;
}
if (height < 0) {
height = 0;
if (height < 1) {
height = 1;
}
if (active_x != view->x ||
active_y != view->y) {
view_move_resize(view, active_x, active_y,
width, height);
} else {
view_resize(view, width, height);
}
view_move_resize(view, x, y, width, height);
}
break;
case ROOTS_CURSOR_ROTATE:
@ -137,7 +132,8 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
struct wlr_surface *surface;
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 &&
view &&
@ -152,14 +148,14 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
case BTN_RIGHT:
edges = 0;
if (sx < view->wlr_surface->current->width/2) {
edges |= ROOTS_CURSOR_RESIZE_EDGE_LEFT;
edges |= WLR_EDGE_LEFT;
} else {
edges |= ROOTS_CURSOR_RESIZE_EDGE_RIGHT;
edges |= WLR_EDGE_RIGHT;
}
if (sy < view->wlr_surface->current->height/2) {
edges |= ROOTS_CURSOR_RESIZE_EDGE_TOP;
edges |= WLR_EDGE_TOP;
} else {
edges |= ROOTS_CURSOR_RESIZE_EDGE_BOTTOM;
edges |= WLR_EDGE_BOTTOM;
}
roots_seat_begin_resize(seat, view, edges);
break;
@ -237,7 +233,7 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
return;
}
double sx, sy;
view_at(desktop, lx, ly, &surface, &sx, &sy);
desktop_view_at(desktop, lx, ly, &surface, &sx, &sy);
uint32_t serial = 0;
if (surface) {
@ -291,7 +287,7 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
}
double sx, sy;
view_at(desktop, lx, ly, &surface, &sx, &sy);
desktop_view_at(desktop, lx, ly, &surface, &sx, &sy);
if (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_xdg_shell_v6.h>
#include <wlr/util/log.h>
#include <server-decoration-protocol.h>
#include "rootston/server.h"
#include "rootston/seat.h"
#include "rootston/xcursor.h"
@ -36,7 +35,7 @@ static void view_update_output(const struct roots_view *view,
struct wlr_box box;
view_get_box(view, &box);
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,
before->x, before->y, before->x + before->width,
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) {
if (view->x == x && view->y == y) {
return;
}
struct wlr_box before;
view_get_box(view, &before);
if (view->move) {
@ -61,6 +64,7 @@ void view_move(struct roots_view *view, double x, double y) {
view->x = x;
view->y = y;
}
view_update_output(view, &before);
}
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,
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) {
view->move_resize(view, x, y, width, height);
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);
}
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) {
if (view->maximized == maximized) {
return;
@ -109,13 +139,7 @@ void view_maximize(struct roots_view *view, bool maximized) {
view->saved.width = view_box.width;
view->saved.height = view_box.height;
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);
struct wlr_output *output = wlr_output_layout_output_at(
view->desktop->layout, output_x, output_y);
struct wlr_output *output = view_get_output(view);
struct wlr_box *output_box =
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) {
if (view->close) {
view->close(view);
@ -181,6 +258,10 @@ bool view_center(struct roots_view *view) {
void view_destroy(struct roots_view *view) {
wl_signal_emit(&view->events.destroy, view);
if (view->fullscreen_output) {
view->fullscreen_output->fullscreen_view = NULL;
}
free(view);
}
@ -198,88 +279,107 @@ void view_setup(struct roots_view *view) {
}
view_center(view);
struct wlr_box before;
view_get_box(view, &before);
view_update_output(view, &before);
view_update_output(view, NULL);
}
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) {
if (view->type == ROOTS_WL_SHELL_VIEW &&
view->wl_shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP) {
return false;
}
double view_sx = lx - view->x;
double view_sy = ly - view->y;
struct wlr_surface_state *state = view->wlr_surface->current;
struct wlr_box box = {
.x = 0,
.y = 0,
.width = state->buffer_width / state->scale,
.height = state->buffer_height / state->scale,
};
if (view->rotation != 0.0) {
// Coordinates relative to the center of the view
double ox = view_sx - (double)box.width/2,
oy = view_sy - (double)box.height/2;
// Rotated coordinates
double rx = cos(view->rotation)*ox - sin(view->rotation)*oy,
ry = cos(view->rotation)*oy + sin(view->rotation)*ox;
view_sx = rx + (double)box.width/2;
view_sy = ry + (double)box.height/2;
}
if (view->type == ROOTS_XDG_SHELL_V6_VIEW) {
double popup_sx, popup_sy;
struct wlr_xdg_surface_v6 *popup =
wlr_xdg_surface_v6_popup_at(view->xdg_surface_v6,
view_sx, view_sy, &popup_sx, &popup_sy);
if (popup) {
*sx = view_sx - popup_sx;
*sy = view_sy - popup_sy;
*surface = popup->surface;
return true;
}
}
if (view->type == ROOTS_WL_SHELL_VIEW) {
double popup_sx, popup_sy;
struct wlr_wl_shell_surface *popup =
wlr_wl_shell_surface_popup_at(view->wl_shell_surface,
view_sx, view_sy, &popup_sx, &popup_sy);
if (popup) {
*sx = view_sx - popup_sx;
*sy = view_sy - popup_sy;
*surface = popup->surface;
return true;
}
}
double sub_x, sub_y;
struct wlr_subsurface *subsurface =
wlr_surface_subsurface_at(view->wlr_surface,
view_sx, view_sy, &sub_x, &sub_y);
if (subsurface) {
*sx = view_sx - sub_x;
*sy = view_sy - sub_y;
*surface = subsurface->surface;
return true;
}
if (wlr_box_contains_point(&box, view_sx, view_sy) &&
pixman_region32_contains_point(&view->wlr_surface->current->input,
view_sx, view_sy, NULL)) {
*sx = view_sx;
*sy = view_sy;
*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->type == ROOTS_WL_SHELL_VIEW &&
view->wl_shell_surface->state ==
WLR_WL_SHELL_SURFACE_STATE_POPUP) {
continue;
}
double view_sx = lx - view->x;
double view_sy = ly - view->y;
struct wlr_surface_state *state = view->wlr_surface->current;
struct wlr_box box = {
.x = 0,
.y = 0,
.width = state->buffer_width / state->scale,
.height = state->buffer_height / state->scale,
};
if (view->rotation != 0.0) {
// Coordinates relative to the center of the view
double ox = view_sx - (double)box.width/2,
oy = view_sy - (double)box.height/2;
// Rotated coordinates
double rx = cos(view->rotation)*ox - sin(view->rotation)*oy,
ry = cos(view->rotation)*oy + sin(view->rotation)*ox;
view_sx = rx + (double)box.width/2;
view_sy = ry + (double)box.height/2;
}
if (view->type == ROOTS_XDG_SHELL_V6_VIEW) {
double popup_sx, popup_sy;
struct wlr_xdg_surface_v6 *popup =
wlr_xdg_surface_v6_popup_at(view->xdg_surface_v6,
view_sx, view_sy, &popup_sx, &popup_sy);
if (popup) {
*sx = view_sx - popup_sx;
*sy = view_sy - popup_sy;
*surface = popup->surface;
return view;
}
}
if (view->type == ROOTS_WL_SHELL_VIEW) {
double popup_sx, popup_sy;
struct wlr_wl_shell_surface *popup =
wlr_wl_shell_surface_popup_at(view->wl_shell_surface,
view_sx, view_sy, &popup_sx, &popup_sy);
if (popup) {
*sx = view_sx - popup_sx;
*sy = view_sy - popup_sy;
*surface = popup->surface;
return view;
}
}
double sub_x, sub_y;
struct wlr_subsurface *subsurface =
wlr_surface_subsurface_at(view->wlr_surface,
view_sx, view_sy, &sub_x, &sub_y);
if (subsurface) {
*sx = view_sx - sub_x;
*sy = view_sy - sub_y;
*surface = subsurface->surface;
return view;
}
if (wlr_box_contains_point(&box, view_sx, view_sy) &&
pixman_region32_contains_point(
&view->wlr_surface->current->input,
view_sx, view_sy, NULL)) {
*sx = view_sx;
*sy = view_sy;
*surface = view->wlr_surface;
if (view_at(view, lx, ly, surface, sx, sy)) {
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_set_default_mode(
desktop->server_decoration_manager,
ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_CLIENT);
WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT);
return desktop;
}
@ -375,3 +475,14 @@ struct roots_desktop *desktop_create(struct roots_server *server,
void desktop_destroy(struct roots_desktop *desktop) {
// 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) {
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) {
roots_seat_cycle_focus(seat);
} 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) {
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 {
wlr_log(L_ERROR, "unknown binding command: %s", command);
}

View file

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

View file

@ -2,6 +2,7 @@
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
#include <GLES2/gl2.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_wl_shell.h>
@ -13,10 +14,6 @@
#include "rootston/desktop.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),
* 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,
&matrix);
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);
}
wlr_surface_send_frame_done(surface, when);
}
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) {
struct wlr_output *wlr_output = data;
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_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;
wl_list_for_each_reverse(view, &desktop->views, link) {
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;
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->phys_height);
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) {
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_layout_add(desktop->layout,
wlr_output, output_config->x, output_config->y);
wlr_output_layout_add(desktop->layout, wlr_output, output_config->x,
output_config->y);
} else {
wlr_output_layout_add_auto(desktop->layout, wlr_output);
}

View file

@ -44,4 +44,5 @@ meta-key = Logo
[bindings]
Logo+Shift+e = exit
Logo+q = close
Logo+m = maximize
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);
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,
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) {

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);
}
static void handle_request_set_maximized(struct wl_listener *listener,
static void handle_request_maximize(struct wl_listener *listener,
void *data) {
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 wlr_wl_shell_surface_set_maximized_event *e = data;
//struct wlr_wl_shell_surface_maximize_event *e = data;
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) {
struct roots_wl_shell_surface *roots_surface =
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) {
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) {
// 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) {
@ -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->request_move.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->surface_commit.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;
wl_signal_add(&surface->events.request_resize,
&roots_surface->request_resize);
roots_surface->request_set_maximized.notify = handle_request_set_maximized;
wl_signal_add(&surface->events.request_set_maximized,
&roots_surface->request_set_maximized);
roots_surface->request_maximize.notify = handle_request_maximize;
wl_signal_add(&surface->events.request_maximize,
&roots_surface->request_maximize);
roots_surface->request_fullscreen.notify =
handle_request_fullscreen;
wl_signal_add(&surface->events.request_fullscreen,
&roots_surface->request_fullscreen);
roots_surface->set_state.notify = handle_set_state;
wl_signal_add(&surface->events.set_state, &roots_surface->set_state);
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit,
&roots_surface->surface_commit);
wl_signal_add(&surface->events.commit, &roots_surface->surface_commit);
struct roots_view *view = calloc(1, sizeof(struct roots_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) {
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) {
box->width = surf->geometry->width;
box->height = surf->geometry->height;
if (surface->geometry->width > 0 && surface->geometry->height > 0) {
box->width = surface->geometry->width;
box->height = surface->geometry->height;
} else {
box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height;
@ -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) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
wlr_xdg_toplevel_v6_set_activated(surf, active);
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
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 *dest_height) {
*dest_width = width;
*dest_height = height;
struct wlr_xdg_toplevel_v6_state *state =
&surf->toplevel_state->current;
struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel_state->current;
if (width < state->min_width) {
*dest_width = state->min_width;
} 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) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->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;
}
uint32_t contrained_width, contrained_height;
apply_size_constraints(surf, width, height, &contrained_width,
&contrained_height);
uint32_t constrained_width, constrained_height;
apply_size_constraints(surface, width, height, &constrained_width,
&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,
uint32_t width, uint32_t height) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
if (surf->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
struct roots_xdg_surface_v6 *roots_surface = view->roots_xdg_surface_v6;
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
return;
}
uint32_t contrained_width, contrained_height;
apply_size_constraints(surf, width, height, &contrained_width,
&contrained_height);
bool update_x = x != view->x;
bool update_y = y != view->y;
x = x + width - contrained_width;
y = y + height - contrained_height;
uint32_t constrained_width, constrained_height;
apply_size_constraints(surface, width, height, &constrained_width,
&constrained_height);
// TODO: we should wait for an ack_configure event before updating the
// position
view->x = x;
view->y = y;
if (update_x) {
x = x + width - constrained_width;
}
if (update_y) {
y = y + height - constrained_height;
}
wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_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->y = y;
}
}
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);
}
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) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
wlr_xdg_toplevel_v6_send_close(surf);
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
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);
}
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) {
//struct roots_xdg_surface_v6 *roots_xdg_surface =
// wl_container_of(listener, roots_xdg_surface, commit);
//struct roots_view *view = roots_xdg_surface->view;
//struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
// TODO
struct roots_xdg_surface_v6 *roots_surface =
wl_container_of(listener, roots_surface, commit);
struct roots_view *view = roots_surface->view;
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
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) {
@ -203,6 +264,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
roots_surface->request_maximize.notify = handle_request_maximize;
wl_signal_add(&surface->events.request_maximize,
&roots_surface->request_maximize);
roots_surface->request_fullscreen.notify = handle_request_fullscreen;
wl_signal_add(&surface->events.request_fullscreen,
&roots_surface->request_fullscreen);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (!view) {
@ -218,6 +282,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->resize = resize;
view->move_resize = move_resize;
view->maximize = maximize;
view->set_fullscreen = set_fullscreen;
view->close = close;
roots_surface->view = view;
view_init(view, desktop);

View file

@ -11,8 +11,7 @@
static void activate(struct roots_view *view, bool active) {
assert(view->type == ROOTS_XWAYLAND_VIEW);
struct wlr_xwayland *xwayland = view->desktop->xwayland;
wlr_xwayland_surface_activate(xwayland, view->xwayland_surface, active);
wlr_xwayland_surface_activate(view->xwayland_surface, active);
}
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;
view->x = x;
view->y = y;
wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface,
x, y, xwayland_surface->width, xwayland_surface->height);
wlr_xwayland_surface_configure(xwayland_surface, x, y,
xwayland_surface->width, xwayland_surface->height);
}
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);
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
uint32_t contrained_width, contrained_height;
apply_size_constraints(xwayland_surface, width, height, &contrained_width,
&contrained_height);
uint32_t constrained_width, constrained_height;
apply_size_constraints(xwayland_surface, width, height, &constrained_width,
&constrained_height);
wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface,
xwayland_surface->x, xwayland_surface->y, contrained_width,
contrained_height);
wlr_xwayland_surface_configure(xwayland_surface, xwayland_surface->x,
xwayland_surface->y, constrained_width, constrained_height);
}
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);
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
uint32_t contrained_width, contrained_height;
apply_size_constraints(xwayland_surface, width, height, &contrained_width,
&contrained_height);
bool update_x = x != view->x;
bool update_y = y != view->y;
x = x + width - contrained_width;
y = y + height - contrained_height;
uint32_t constrained_width, constrained_height;
apply_size_constraints(xwayland_surface, width, height, &constrained_width,
&constrained_height);
view->x = x;
view->y = y;
if (update_x) {
x = x + width - constrained_width;
}
if (update_y) {
y = y + height - constrained_height;
}
wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface,
x, y, contrained_width, contrained_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;
wlr_xwayland_surface_configure(xwayland_surface, x, y, constrained_width,
constrained_height);
}
static void close(struct roots_view *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) {
assert(view->type == ROOTS_XWAYLAND_VIEW);
wlr_xwayland_surface_set_maximized(view->desktop->xwayland,
view->xwayland_surface, maximized);
wlr_xwayland_surface_set_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) {
@ -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->y = (double)event->y;
wlr_xwayland_surface_configure(roots_surface->view->desktop->xwayland,
xwayland_surface, event->x, event->y, event->width, event->height);
wlr_xwayland_surface_configure(xwayland_surface, event->x, event->y,
event->width, event->height);
}
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);
}
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) {
struct roots_xwayland_surface *roots_surface =
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->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);
}
@ -194,6 +243,8 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) {
wl_container_of(listener, roots_surface, unmap_notify);
roots_surface->view->wlr_surface = NULL;
wl_list_remove(&roots_surface->surface_commit.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;
wl_signal_add(&surface->events.request_maximize,
&roots_surface->request_maximize);
roots_surface->request_fullscreen.notify = handle_request_fullscreen;
wl_signal_add(&surface->events.request_fullscreen,
&roots_surface->request_fullscreen);
roots_surface->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));
if (view == NULL) {
@ -245,6 +303,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->move = move;
view->move_resize = move_resize;
view->maximize = maximize;
view->set_fullscreen = set_fullscreen;
view->close = close;
roots_surface->view = view;
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(
struct wl_resource *resource) {
assert(resource);
struct wlr_output *output = wl_resource_get_user_data(resource);
assert(output);
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,
&wl_output_interface, 3, wlr_output, wl_output_bind);
wlr_output->wl_global = wl_global;
wl_list_init(&wlr_output->wl_resources);
return wl_global;
}
@ -155,6 +155,7 @@ bool wlr_output_set_mode(struct wlr_output *output,
bool result = output->impl->set_mode(output, mode);
if (result) {
wlr_output_update_matrix(output);
struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) {
wlr_output_send_current_mode_to_resource(resource);
@ -168,14 +169,14 @@ void wlr_output_update_size(struct wlr_output *output, int32_t width,
if (output->width == width && output->height == height) {
return;
}
output->width = width;
output->height = height;
wlr_output_update_matrix(output);
if (output->wl_global != NULL) {
struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) {
wlr_output_send_current_mode_to_resource(resource);
}
struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) {
wlr_output_send_current_mode_to_resource(resource);
}
}
@ -183,6 +184,12 @@ void wlr_output_transform(struct wlr_output *output,
enum wl_output_transform transform) {
output->impl->transform(output, transform);
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,
@ -194,6 +201,21 @@ void wlr_output_set_position(struct wlr_output *output, int32_t lx,
output->lx = lx;
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;
wl_resource_for_each(resource, &output->wl_resources) {
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->scale = 1;
wl_list_init(&output->cursors);
wl_list_init(&output->wl_resources);
wl_signal_init(&output->events.frame);
wl_signal_init(&output->events.swap_buffers);
wl_signal_init(&output->events.resolution);
@ -251,15 +274,60 @@ void wlr_output_make_current(struct wlr_output *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,
struct wlr_box *box) {
box->x = cursor->x - cursor->hotspot_x;
box->y = cursor->y - cursor->hotspot_y;
box->width = cursor->width;
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_renderer *renderer = cursor->renderer;
if (cursor->surface != NULL) {
@ -271,48 +339,48 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) {
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);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
int x = cursor->x - cursor->hotspot_x;
int y = cursor->y - cursor->hotspot_y;
if (cursor->surface != NULL) {
x += cursor->surface->current->sx;
y += cursor->surface->current->sy;
}
struct wlr_box cursor_box;
output_cursor_get_box(cursor, &cursor_box);
float translate[16];
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];
wlr_texture_get_matrix(texture, &matrix, &cursor->output->transform_matrix,
x, y);
wlr_matrix_mul(&translate, &scale, &matrix);
wlr_matrix_mul(&cursor->output->transform_matrix, &matrix, &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) {
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;
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;
}
output_cursor_render(cursor);
output_cursor_render(cursor, &now);
}
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);
}
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) {
if (cursor->output->hardware_cursor != cursor) {
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 &&
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,
stride, width, height, hotspot_x, hotspot_y, true);
if (ok) {
@ -390,40 +512,56 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
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) {
// Some clients commit a cursor surface with a NULL buffer to hide it.
cursor->enabled = wlr_surface_has_buffer(cursor->surface);
cursor->width = cursor->surface->current->width;
cursor->height = cursor->surface->current->height;
cursor->width = cursor->surface->current->width * cursor->output->scale;
cursor->height = cursor->surface->current->height * cursor->output->scale;
if (cursor->output->hardware_cursor != cursor) {
cursor->output->needs_swap = true;
} else {
// TODO: upload pixels
}
}
static inline int64_t timespec_to_msec(const struct timespec *a) {
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
wlr_surface_send_frame_done(cursor->surface, &now);
}
}
static void output_cursor_handle_commit(struct wl_listener *listener,
void *data) {
struct wlr_output_cursor *cursor = wl_container_of(listener, cursor,
surface_commit);
struct wlr_surface *surface = data;
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,
@ -439,8 +577,8 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor,
return;
}
cursor->hotspot_x = hotspot_x;
cursor->hotspot_y = hotspot_y;
cursor->hotspot_x = hotspot_x * cursor->output->scale;
cursor->hotspot_y = hotspot_y * cursor->output->scale;
if (surface && surface == cursor->surface) {
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.destroy, &cursor->surface_destroy);
output_cursor_commit(cursor);
cursor->visible = false;
output_cursor_update_visible(cursor);
} else {
cursor->enabled = false;
cursor->width = 0;
@ -485,6 +626,7 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor,
y *= cursor->output->scale;
cursor->x = x;
cursor->y = y;
output_cursor_update_visible(cursor);
if (cursor->output->hardware_cursor != cursor) {
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,
struct wl_resource *resource, struct wl_resource *seat_resource,
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_seat_client *seat =
wl_resource_get_user_data(seat_resource);
struct wlr_wl_shell_surface_move_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_move_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
struct wlr_wl_shell_surface_move_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
};
wl_signal_emit(&surface->events.request_move, event);
free(event);
wl_signal_emit(&surface->events.request_move, &event);
}
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,
struct wl_resource *resource, struct wl_resource *seat_resource,
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_seat_client *seat =
wl_resource_get_user_data(seat_resource);
struct wlr_wl_shell_surface_resize_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_resize_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
event->edges = edges;
struct wlr_wl_shell_surface_resize_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
.edges = edges,
};
wl_signal_emit(&surface->events.request_resize, event);
free(event);
wl_signal_emit(&surface->events.request_resize, &event);
}
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,
enum wl_shell_surface_fullscreen_method method, uint32_t framerate,
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_output *output = NULL;
if (output_resource != NULL) {
@ -289,24 +272,16 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client,
shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN,
NULL, NULL);
struct wlr_wl_shell_surface_set_fullscreen_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_set_fullscreen_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
event->client = client;
event->surface = surface;
event->method = method;
event->framerate = framerate;
event->output = output;
struct wlr_wl_shell_surface_set_fullscreen_event event = {
.surface = surface,
.method = method,
.framerate = framerate,
.output = output,
};
wl_signal_emit(&surface->events.request_set_fullscreen, event);
free(event);
wl_signal_emit(&surface->events.request_fullscreen, &event);
}
static void shell_surface_protocol_set_popup(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, struct wl_resource *parent_resource, int32_t x,
@ -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,
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_output *output = 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,
NULL, NULL);
struct wlr_wl_shell_surface_set_maximized_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_set_maximized_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
event->client = client;
event->surface = surface;
event->output = output;
struct wlr_wl_shell_surface_maximize_event event = {
.surface = surface,
.output = output,
};
wl_signal_emit(&surface->events.request_set_maximized, event);
free(event);
wl_signal_emit(&surface->events.request_maximize, &event);
}
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);
shell_pointer_grab_maybe_end(&grab->pointer_grab);
}
wl_signal_emit(&surface->events.commit, surface);
}
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_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.request_move);
wl_signal_init(&wl_surface->events.request_resize);
wl_signal_init(&wl_surface->events.request_set_fullscreen);
wl_signal_init(&wl_surface->events.request_set_maximized);
wl_signal_init(&wl_surface->events.request_fullscreen);
wl_signal_init(&wl_surface->events.request_maximize);
wl_signal_init(&wl_surface->events.set_state);
wl_signal_init(&wl_surface->events.set_title);
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;
}
struct wlr_xdg_toplevel_v6_show_window_menu_event *event =
calloc(1, sizeof(struct wlr_xdg_toplevel_v6_show_window_menu_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
struct wlr_xdg_toplevel_v6_show_window_menu_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
.x = x,
.y = y,
};
event->client = client;
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);
wl_signal_emit(&surface->events.request_show_window_menu, &event);
}
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;
}
struct wlr_xdg_toplevel_v6_move_event *event =
calloc(1, sizeof(struct wlr_xdg_toplevel_v6_move_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
struct wlr_xdg_toplevel_v6_move_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
};
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
wl_signal_emit(&surface->events.request_move, event);
free(event);
wl_signal_emit(&surface->events.request_move, &event);
}
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;
}
struct wlr_xdg_toplevel_v6_resize_event *event =
calloc(1, sizeof(struct wlr_xdg_toplevel_v6_resize_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
struct wlr_xdg_toplevel_v6_resize_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
.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);
free(event);
wl_signal_emit(&surface->events.request_resize, &event);
}
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,
struct wl_resource *resource, struct wl_resource *output_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;
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,
struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
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,
@ -812,8 +809,7 @@ static void xdg_surface_ack_configure(struct wl_client *client,
}
surface->configured = true;
wl_signal_emit(&surface->events.ack_configure, surface);
surface->configure_serial = serial;
free(configure);
}
@ -941,7 +937,6 @@ static void wlr_xdg_toplevel_v6_send_configure(
static void wlr_xdg_surface_send_configure(void *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;
@ -953,7 +948,7 @@ static void wlr_xdg_surface_send_configure(void *user_data) {
}
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) {
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);
}
static void wlr_xdg_surface_v6_schedule_configure(
static uint32_t wlr_xdg_surface_v6_schedule_configure(
struct wlr_xdg_surface_v6 *surface) {
struct wl_display *display = wl_client_get_display(surface->client->client);
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 (!pending_same) {
// configure request already scheduled
return;
return surface->configure_next_serial;
}
// configure request not necessary anymore
wl_event_source_remove(surface->configure_idle);
surface->configure_idle = NULL;
return 0;
} else {
if (pending_same) {
// configure request not necessary
return;
return 0;
}
surface->configure_idle =
wl_event_loop_add_idle(
loop,
wlr_xdg_surface_send_configure,
surface);
surface->configure_next_serial = wl_display_next_serial(display);
surface->configure_idle = wl_event_loop_add_idle(loop,
wlr_xdg_surface_send_configure, surface);
return surface->configure_next_serial;
}
}
@ -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.commit);
wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.ack_configure);
wl_signal_init(&surface->events.ping_timeout);
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);
}
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) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
surface->toplevel_state->pending.width = width;
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) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
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) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
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) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
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) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
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) {

View file

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

View file

@ -29,15 +29,11 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#ifdef __linux__
#include <sys/epoll.h>
#endif
#include <string.h>
#include <stdlib.h>
#include "util/os-compatibility.h"
int
os_fd_set_cloexec(int fd)
{
int os_fd_set_cloexec(int fd) {
long flags;
if (fd == -1)
@ -53,9 +49,7 @@ os_fd_set_cloexec(int fd)
return 0;
}
static int
set_cloexec_or_close(int fd)
{
int set_cloexec_or_close(int fd) {
if (os_fd_set_cloexec(fd) != 0) {
close(fd);
return -1;
@ -63,8 +57,7 @@ set_cloexec_or_close(int fd)
return fd;
}
static int
create_tmpfile_cloexec(char *tmpname)
int create_tmpfile_cloexec(char *tmpname)
{
int fd;
@ -104,9 +97,7 @@ create_tmpfile_cloexec(char *tmpname)
* If posix_fallocate() is not supported, program may receive
* SIGBUS on accessing mmap()'ed file contents instead.
*/
int
os_create_anonymous_file(off_t size)
{
int os_create_anonymous_file(off_t size) {
static const char template[] = "/wlroots-shared-XXXXXX";
const char *path;
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) {
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 *socket_dir = "/tmp/.X11-unix";
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) {
int fd, rc;
@ -73,7 +76,7 @@ static bool open_sockets(int socks[2], int display) {
addr.sun_path[0] = 0;
path_size = snprintf(addr.sun_path + 1, sizeof(addr.sun_path) - 1, socket_fmt, display);
#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
socks[0] = open_socket(&addr, path_size);
if (socks[0] < 0) {
@ -97,6 +100,11 @@ void unlink_display_sockets(int display) {
snprintf(sun_path, sizeof(sun_path), socket_fmt, display);
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);
unlink(sun_path);
}

View file

@ -8,6 +8,7 @@
#include <xcb/xcb_image.h>
#include <xcb/render.h>
#include "wlr/util/log.h"
#include "wlr/util/edges.h"
#include "wlr/types/wlr_surface.h"
#include "wlr/xwayland.h"
#include "wlr/xcursor.h"
@ -598,7 +599,7 @@ static void xwm_handle_configure_request(struct wlr_xwm *xwm,
if (xsurface->surface == NULL) {
// 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);
} else {
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_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,
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);
if (!xsurface) {
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_LEFT:
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);
break;
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,
struct wlr_xwayland_surface *xsurface, bool activated) {
struct wlr_xwayland_surface *focused = wlr_xwayland->xwm->focus_surface;
void wlr_xwayland_surface_activate(struct wlr_xwayland_surface *xsurface,
bool activated) {
struct wlr_xwayland_surface *focused = xsurface->xwm->focus_surface;
if (activated) {
xwm_surface_activate(wlr_xwayland->xwm, xsurface);
xwm_surface_activate(xsurface->xwm, 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,
struct wlr_xwayland_surface *xsurface, int16_t x, int16_t y,
uint16_t width, uint16_t height) {
void wlr_xwayland_surface_configure(struct wlr_xwayland_surface *xsurface,
int16_t x, int16_t y, uint16_t width, uint16_t height) {
xsurface->x = x;
xsurface->y = y;
xsurface->width = width;
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 |
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
XCB_CONFIG_WINDOW_BORDER_WIDTH;
@ -1022,9 +1051,8 @@ void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland,
xcb_flush(xwm->xcb_conn);
}
void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland,
struct wlr_xwayland_surface *xsurface) {
struct wlr_xwm *xwm = wlr_xwayland->xwm;
void wlr_xwayland_surface_close(struct wlr_xwayland_surface *xsurface) {
struct wlr_xwm *xwm = xsurface->xwm;
bool supports_delete = false;
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;
}
void wlr_xwayland_surface_set_maximized(struct wlr_xwayland *wlr_xwayland,
struct wlr_xwayland_surface *surface, bool maximized) {
if (xsurface_is_maximized(surface) != maximized) {
surface->maximized_horz = maximized;
surface->maximized_vert = maximized;
xsurface_set_net_wm_state(surface);
}
void wlr_xwayland_surface_set_maximized(struct wlr_xwayland_surface *surface,
bool maximized) {
surface->maximized_horz = maximized;
surface->maximized_vert = maximized;
xsurface_set_net_wm_state(surface);
xcb_flush(surface->xwm->xcb_conn);
}
void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland *wlr_xwayland,
struct wlr_xwayland_surface *surface, bool fullscreen) {
if (surface->fullscreen != fullscreen) {
surface->fullscreen = fullscreen;
xsurface_set_net_wm_state(surface);
}
void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland_surface *surface,
bool fullscreen) {
surface->fullscreen = fullscreen;
xsurface_set_net_wm_state(surface);
xcb_flush(surface->xwm->xcb_conn);
}