refactor + add request set selection handles

This commit is contained in:
DanyLE 2024-04-01 23:51:48 +02:00
parent 0d84bd388c
commit 68b1890d61
5 changed files with 47 additions and 22 deletions

View File

@ -248,7 +248,6 @@ static void server_cursor_button(struct wl_listener *listener, void *data)
else
{
diyac_cursor_focus(seat->server);
}
}

View File

@ -4,8 +4,6 @@
#include <unistd.h>
#include <getopt.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_fractional_scale_v1.h>
#include "output.h"
#include "xdg.h"
#include "cursor.h"

View File

@ -12,6 +12,8 @@
#include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_fractional_scale_v1.h>
#define LAYER_TREE_SZ 4
@ -62,6 +64,7 @@ struct diyac_seat
struct wl_listener new_input;
struct wl_listener request_cursor;
struct wl_listener request_set_selection;
struct wl_listener request_set_primary_selection;
struct wl_list keyboards;
};

26
seat.c
View File

@ -216,6 +216,24 @@ static void seat_request_set_selection(struct wl_listener *listener, void *data)
wlr_seat_set_selection(seat->wlr_seat, event->source, event->serial);
}
static void request_set_selection_notify(struct wl_listener *listener, void *data)
{
struct diyac_seat *seat = wl_container_of(
listener, seat, request_set_selection);
struct wlr_seat_request_set_selection_event *event = data;
wlr_seat_set_selection(seat->wlr_seat, event->source,
event->serial);
}
static void request_set_primary_selection_notify(struct wl_listener *listener, void *data)
{
struct diyac_seat *seat = wl_container_of(
listener, seat, request_set_primary_selection);
struct wlr_seat_request_set_primary_selection_event *event = data;
wlr_seat_set_primary_selection(seat->wlr_seat, event->source,
event->serial);
}
/*
* Configures a seat, which is a single "seat" at which a user sits and
* operates the computer. This conceptually includes up to one keyboard,
@ -235,6 +253,14 @@ void diyac_init_seat(struct diyac_server *server)
server->seat.request_set_selection.notify = seat_request_set_selection;
wl_signal_add(&server->seat.wlr_seat->events.request_set_selection,
&server->seat.request_set_selection);
server->seat.request_set_selection.notify = request_set_selection_notify;
wl_signal_add(&server->seat.wlr_seat->events.request_set_selection,
&server->seat.request_set_selection);
server->seat.request_set_primary_selection.notify =
request_set_primary_selection_notify;
wl_signal_add(&server->seat.wlr_seat->events.request_set_primary_selection,
&server->seat.request_set_primary_selection);
}
static void seat_focus(struct diyac_seat *seat, struct wlr_surface *surface, bool is_lock_surface)

15
xdg.c
View File

@ -55,8 +55,15 @@ static void begin_interactive(struct diyac_view *toplevel,
static void xdg_toplevel_map(struct wl_listener *listener, void *data)
{
/* Called when the surface is mapped, or ready to display on-screen. */
struct diyac_view *toplevel = wl_container_of(listener, toplevel, map);
/*
wlr_xdg_toplevel_set_wm_capabilities(toplevel->xdg_toplevel,
WLR_XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE |
WLR_XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE);
//WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN
*/
wlr_xdg_surface_get_geometry(toplevel->xdg_toplevel->base, &toplevel->original);
wlr_scene_node_set_enabled(&toplevel->scene_tree->node, true);
toplevel->mapped = true;
@ -157,13 +164,6 @@ static void xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *
{
struct diyac_view *toplevel =
wl_container_of(listener, toplevel, request_fullscreen);
wlr_log(WLR_INFO, "Cursor state %d", toplevel->server->seat.cursor_mode);
if (toplevel->server->seat.cursor_mode != DIYAC_CURSOR_PASSTHROUGH)
{
wlr_log(WLR_INFO, "The view is under move/resize, disable fullcreen event");
wlr_xdg_toplevel_set_fullscreen(toplevel->xdg_toplevel, false);
return;
}
if (!toplevel->mapped)
{
wlr_xdg_toplevel_set_fullscreen(toplevel->xdg_toplevel, false);
@ -175,7 +175,6 @@ static void xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *
diyac_reset_cursor_mode(toplevel->server);
wlr_xdg_toplevel_set_fullscreen(toplevel->xdg_toplevel, false);
/*
if (toplevel->state == DIYAC_VIEW_FULL_SCREEN)
{
toplevel->state = DIYAC_VIEW_NORMAL;