-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement foundation for pointer constraints
- Loading branch information
Showing
7 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "constraint.hpp" | ||
|
||
#include "seat.hpp" | ||
#include "types.hpp" | ||
|
||
#include <wayland-util.h> | ||
|
||
#include "wlr-wrap-start.hpp" | ||
#include <wlr/types/wlr_compositor.h> | ||
#include "wlr-wrap-end.hpp" | ||
|
||
static void constraint_set_region_notify(wl_listener* listener, void* data) { | ||
(void) listener; | ||
(void) data; | ||
} | ||
|
||
static void constraint_surface_commit_notify(wl_listener* listener, void* data) { | ||
(void) listener; | ||
(void) data; | ||
} | ||
|
||
static void constraint_destroy_notify(wl_listener* listener, void* data) { | ||
PointerConstraint& constraint = magpie_container_of(listener, constraint, destroy); | ||
(void) data; | ||
|
||
auto& current_constraint = constraint.seat.current_constraint; | ||
if (current_constraint.has_value() && current_constraint.value().wlr == constraint.wlr) { | ||
current_constraint.reset(); | ||
} | ||
} | ||
|
||
PointerConstraint::PointerConstraint(Seat& seat, wlr_pointer_constraint_v1* constraint) noexcept | ||
: listeners(*this), seat(seat), wlr(constraint) { | ||
listeners.set_region.notify = constraint_set_region_notify; | ||
wl_signal_add(&constraint->events.set_region, &listeners.set_region); | ||
listeners.surface_commit.notify = constraint_surface_commit_notify; | ||
wl_signal_add(&constraint->surface->events.commit, &listeners.surface_commit); | ||
listeners.destroy.notify = constraint_destroy_notify; | ||
wl_signal_add(&constraint->events.destroy, &listeners.destroy); | ||
} | ||
|
||
PointerConstraint::~PointerConstraint() noexcept { | ||
deactivate(); | ||
wl_list_remove(&listeners.set_region.link); | ||
wl_list_remove(&listeners.surface_commit.link); | ||
wl_list_remove(&listeners.destroy.link); | ||
} | ||
|
||
void PointerConstraint::activate() const { | ||
wlr_pointer_constraint_v1_send_activated(wlr); | ||
} | ||
|
||
void PointerConstraint::deactivate() const { | ||
wlr_pointer_constraint_v1_send_deactivated(wlr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef MAGPIE_CONSTRAINT_HPP | ||
#define MAGPIE_CONSTRAINT_HPP | ||
|
||
#include "types.hpp" | ||
|
||
#include <functional> | ||
#include <wayland-server-core.h> | ||
|
||
#include "wlr-wrap-start.hpp" | ||
#include <wlr/types/wlr_pointer_constraints_v1.h> | ||
#include "wlr-wrap-end.hpp" | ||
|
||
class PointerConstraint { | ||
public: | ||
struct Listeners { | ||
std::reference_wrapper<PointerConstraint> parent; | ||
wl_listener set_region; | ||
wl_listener surface_commit; | ||
wl_listener destroy; | ||
Listeners(PointerConstraint& parent) noexcept : parent(parent) {} | ||
}; | ||
|
||
private: | ||
Listeners listeners; | ||
|
||
public: | ||
Seat& seat; | ||
wlr_pointer_constraint_v1* wlr; | ||
|
||
PointerConstraint(Seat& seat, wlr_pointer_constraint_v1* wlr) noexcept; | ||
~PointerConstraint() noexcept; | ||
|
||
void activate() const; | ||
void deactivate() const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters