Skip to content

Commit

Permalink
core: use existing idle-inhibit framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Nov 22, 2023
1 parent f4ea727 commit 33b165c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/api/wayfire/idle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class idle_inhibitor_t

private:
static unsigned int inhibitors;
void notify_wlroots();
void notify_update();
};
}
2 changes: 0 additions & 2 deletions src/core/core-impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class compositor_core_impl_t : public compositor_core_t
wf::wl_listener_wrapper vptr_created;
wf::wl_listener_wrapper input_inhibit_activated;
wf::wl_listener_wrapper input_inhibit_deactivated;
wf::wl_listener_wrapper idle_inhibitor_new;
wf::wl_listener_wrapper idle_inhibitor_destroy;
wf::wl_listener_wrapper pointer_constraint_added;
wf::wl_listener_wrapper idle_inhibitor_created;
std::shared_ptr<scene::root_node_t> scene_root;
Expand Down
27 changes: 7 additions & 20 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,16 @@ void wf::compositor_core_impl_t::init()
input_inhibit_deactivated.connect(&protocols.input_inhibit->events.deactivate);

/* idle-inhibit setup */
input->inhibitor_ref_count = 0;
protocols.idle_inhibit = wlr_idle_inhibit_v1_create(display);
idle_inhibitor_new.set_callback([&] (void*)
{
input->send_inhibit_changed_signal(++input->inhibitor_ref_count);
});
idle_inhibitor_new.connect(&protocols.idle_inhibit->events.new_inhibitor);
protocols.idle_notifier = wlr_idle_notifier_v1_create(display);
protocols.idle_inhibit = wlr_idle_inhibit_v1_create(display);

idle_inhibitor_destroy.set_callback([&] (void*)
idle_inhibitor_created.set_callback([&] (void *data)
{
input->send_inhibit_changed_signal(--input->inhibitor_ref_count);
auto wlri = static_cast<wlr_idle_inhibitor_v1*>(data);
/* will be freed by the destroy request */
new wlr_idle_inhibitor_t(wlri);
});
idle_inhibitor_destroy.connect(&protocols.idle_inhibit->events.destroy);
idle_inhibitor_created.connect(&protocols.idle_inhibit->events.new_inhibitor);

/* decoration_manager setup */
protocols.decorator_manager = wlr_server_decoration_manager_create(display);
Expand All @@ -169,16 +166,6 @@ void wf::compositor_core_impl_t::init()
});
vptr_created.connect(&protocols.vptr_manager->events.new_virtual_pointer);

protocols.idle_notifier = wlr_idle_notifier_v1_create(display);
idle_inhibitor_created.set_callback([&] (void *data)
{
auto wlri = static_cast<wlr_idle_inhibitor_v1*>(data);
/* will be freed by the destroy request */
new wlr_idle_inhibitor_t(wlri);
});
idle_inhibitor_created.connect(
&protocols.idle_inhibit->events.new_inhibitor);

protocols.pointer_gestures = wlr_pointer_gestures_v1_create(display);
protocols.relative_pointer = wlr_relative_pointer_manager_v1_create(display);

Expand Down
11 changes: 7 additions & 4 deletions src/core/idle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@

unsigned int wf::idle_inhibitor_t::inhibitors = 0;

void wf::idle_inhibitor_t::notify_wlroots()
void wf::idle_inhibitor_t::notify_update()
{
/* NOTE: inhibited -> NOT enabled */
wlr_idle_notifier_v1_set_inhibited(wf::get_core().protocols.idle_notifier, inhibitors == 0);
wf::get_core_impl().input->send_inhibit_changed_signal(inhibitors);

wf::input_inhibit_changed_signal data;
data.inhibit = (inhibitors != 0);
wf::get_core().emit(&data);
}

wf::idle_inhibitor_t::idle_inhibitor_t()
{
LOGD("creating idle inhibitor ", this, " previous count: ", inhibitors);
inhibitors++;
notify_wlroots();
notify_update();
}

wf::idle_inhibitor_t::~idle_inhibitor_t()
{
LOGD("destroying idle inhibitor ", this, " previous count: ", inhibitors);
inhibitors--;
notify_wlroots();
notify_update();
}
7 changes: 0 additions & 7 deletions src/core/seat/input-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,6 @@ wf::input_manager_t::input_manager_t()
wf::get_core().output_layout->connect(&output_added);
}

void wf::input_manager_t::send_inhibit_changed_signal(int ref_count)
{
wf::input_inhibit_changed_signal data;
data.inhibit = (ref_count != 0);
wf::get_core().emit(&data);
}

void wf::input_manager_t::set_exclusive_focus(wl_client *client)
{
exclusive_client = client;
Expand Down
12 changes: 0 additions & 12 deletions src/core/seat/input-manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,6 @@ class input_manager_t
*/
void set_exclusive_focus(wl_client *client);

/**
* Send inhibit changed signal.
* When ref_count is 0, send uninhibit. Else send inhibit.
*/
void send_inhibit_changed_signal(int ref_count);

/**
* The inhibit ref count variable.
*/
int inhibitor_ref_count;


std::vector<std::unique_ptr<wf::input_device_impl_t>> input_devices;
};
}
Expand Down

0 comments on commit 33b165c

Please sign in to comment.