Skip to content

Commit

Permalink
Merge pull request #85 from anriha/primary-selection
Browse files Browse the repository at this point in the history
Added proper support for primary selection
  • Loading branch information
flacjacket authored May 16, 2022
2 parents 13e043f + cf2e03c commit 0d13482
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
13 changes: 13 additions & 0 deletions wlroots/ffi_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,12 @@ def has_xwayland() -> bool:
wlr_primary_selection_v1_device_manager_create(struct wl_display *display);
"""

# types/wlr_primary_selection.h
CDEF += """
void wlr_seat_set_primary_selection(struct wlr_seat *seat,
struct wlr_primary_selection_source *source, uint32_t serial);
"""

# types/wlr_relative_pointer_v1.h
CDEF += """
struct wlr_relative_pointer_manager_v1 {
Expand Down Expand Up @@ -1582,6 +1588,12 @@ def has_xwayland() -> bool:
...;
};
struct wlr_seat_request_set_primary_selection_event {
struct wlr_primary_selection_source *source;
uint32_t serial;
...;
};
struct wlr_seat_request_start_drag_event {
struct wlr_drag *drag;
struct wlr_surface *origin;
Expand Down Expand Up @@ -2322,6 +2334,7 @@ def has_xwayland() -> bool:
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_output_power_management_v1.h>
#include <wlr/types/wlr_pointer_constraints_v1.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/types/wlr_scene.h>
Expand Down
23 changes: 19 additions & 4 deletions wlroots/wlr_types/seat.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ def __init__(self, display: Display, name: str) -> None:
)
# Called after the data source is set for the selection
self.set_selection_event = Signal(
ptr=ffi.addressof(self._ptr.events.set_selection),
data_wrapper=RequestSetPrimarySelectionEvent,
ptr=ffi.addressof(self._ptr.events.set_selection)
)

# Called when an application _wants_ to set the primary selection (user selects some data)
self.request_set_primary_selection_event = Signal(
ptr=ffi.addressof(self._ptr.events.request_set_primary_selection)
ptr=ffi.addressof(self._ptr.events.request_set_primary_selection),
data_wrapper=RequestSetPrimarySelectionEvent,
)
# Called after the primary selection source object is set
self.set_primary_selection_event = Signal(
Expand Down Expand Up @@ -330,6 +330,19 @@ def set_selection(self, source, serial: int) -> None:
# TODO: wrap source in a data source
lib.wlr_seat_set_selection(self._ptr, source, serial)

def set_primary_selection(self, source, serial: int) -> None:
"""Sets the current primary selection for the seat.
None can be provided to clear it. This removes the previous one if
there was any. In case the selection doesn't come from a client,
Display.next_serial() can be used to generate a serial.
"""
if source is None:
lib.wlr_seat_set_primary_selection(self._ptr, ffi.NULL, serial)
else:
# TODO: wrap source in a data source
lib.wlr_seat_set_primary_selection(self._ptr, source, serial)

def validate_pointer_grab_serial(self, origin: Surface, serial: int) -> bool:
"""Check whether this serial is valid to start a pointer grab action."""
return lib.wlr_seat_validate_pointer_grab_serial(self._ptr, origin._ptr, serial)
Expand Down Expand Up @@ -383,7 +396,9 @@ def serial(self) -> int:

class RequestSetPrimarySelectionEvent(Ptr):
def __init__(self, ptr) -> None:
self._ptr = ffi.cast("struct wlr_seat_request_set_selection_event *", ptr)
self._ptr = ffi.cast(
"struct wlr_seat_request_set_primary_selection_event *", ptr
)

# TODO: source

Expand Down

0 comments on commit 0d13482

Please sign in to comment.