Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions metadata/hide-cursor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@
<default>2000</default>
<min>250</min>
</option>
<option name="disabled_for" type="string">
<_short>Disabled for specified window types</_short>
<_long>Disables cursor hiding for windows matching the specified criteria.</_long>
<default>none</default>
</option>
</plugin>
</wayfire>
33 changes: 19 additions & 14 deletions metadata/keycolor.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<?xml version="1.0"?>
<wayfire>
<plugin name="keycolor">
<_short>Keycolor</_short>
<category>Effects</category>
<option name="color" type="color">
<_short>Key Color</_short>
<default>0 0 0 1</default>
</option>
<option name="opacity" type="double">
<_short>Opacity</_short>
<default>0.25</default>
</option>
<option name="threshold" type="double">
<_short>Threshold</_short>
<default>0.5</default>
</option>
<_short>Keycolor</_short>
<category>Effects</category>
<option name="color" type="color">
<_short>Key Color</_short>
<default>0 0 0 1</default>
</option>
<option name="opacity" type="double">
<_short>Opacity</_short>
<default>0.25</default>
</option>
<option name="threshold" type="double">
<_short>Threshold</_short>
<default>0.5</default>
</option>
<option name="enabled_for" type="string">
<_short>Keycolor enabled for specified windows</_short>
<_long>Specifies the windows for which the keycolor effect is enabled.</_long>
<default>type equals "toplevel"</default>
</option>
</plugin>
</wayfire>
114 changes: 82 additions & 32 deletions src/hide-cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <wayfire/matcher.hpp>
#include <wayfire/plugins/common/shared-core-data.hpp>
#include <wayfire/per-output-plugin.hpp>
#include <wayfire/plugin.hpp>
Expand All @@ -30,53 +31,101 @@

namespace wf_hide_cursor
{

bool hidden;

class wayfire_hide_cursor
{
wf::option_wrapper_t<int> hide_delay{"hide-cursor/hide_delay"};
wf::view_matcher_t disabled_for{"hide-cursor/disabled_for"};
wf::wl_timer<false> hide_timer;

void restart_hide_timer()
{
hide_timer.disconnect();
hide_timer.set_timeout(hide_delay, [=] ()
{
hide_or_show_cursor();
});
}

void hide_or_show_cursor()
{
auto view = wf::get_core().get_cursor_focus_view();

if (view && disabled_for.matches(view))
{
show_cursor();
} else
{
hide_cursor();
}
}

public:
wayfire_hide_cursor()
void hide_cursor()
{
hide_timer.disconnect();

if (hidden)
return;

wf::get_core().hide_cursor();
hidden = true;
}

void show_cursor()
{
hide_timer.disconnect();

if (!hidden)
return;

wf::get_core().unhide_cursor();
hidden = false;
setup_hide_timer();
wf::get_core().connect(&pointer_motion);
}

wf::signal::connection_t<wf::input_event_signal<wlr_pointer_motion_event>> pointer_motion =
[=] (wf::input_event_signal<wlr_pointer_motion_event> *ev)
void toggle_cursor()
{
setup_hide_timer();
if (hidden)
{
wf::get_core().unhide_cursor();
hidden = false;
show_cursor();
} else
{
hide_cursor();
}
};
}

void setup_hide_timer()
wayfire_hide_cursor()
{
hide_timer.disconnect();
hide_timer.set_timeout(hide_delay, [=] ()
hidden = false;
restart_hide_timer();

wf::get_core().connect(&pointer_motion);
}

void on_event()
{
if (hidden)
{
if (!hidden)
{
wf::get_core().hide_cursor();
hidden = true;
}
});
show_cursor();
}

restart_hide_timer();
}

wf::signal::connection_t<wf::input_event_signal<wlr_pointer_motion_event>> pointer_motion =
[=] (wf::input_event_signal<wlr_pointer_motion_event> *ev)
{
on_event();
};

~wayfire_hide_cursor()
{
pointer_motion.disconnect();
hide_timer.disconnect();
if (hidden)
{
wf::get_core().unhide_cursor();
}

show_cursor();
}
};

Expand All @@ -86,32 +135,33 @@ class wayfire_hide_cursor_plugin : public wf::per_output_plugin_instance_t

wf::activator_callback toggle_cb = [=] (auto)
{
hidden = !hidden;

if (hidden)
{
wf::get_core().hide_cursor();
} else
{
wf::get_core().unhide_cursor();
}

global_idle->toggle_cursor();
return true;
};

wf::signal::connection_t<wf::workspace_changed_signal> workspace_changed =
[=] (wf::workspace_changed_signal *ev)
{
global_idle->on_event();
};

public:
void init() override
{
output->add_activator(
wf::option_wrapper_t<wf::activatorbinding_t>{"hide-cursor/toggle"},
&toggle_cb);

output->connect(&workspace_changed);
}

void fini() override
{
output->rem_binding(&toggle_cb);
workspace_changed.disconnect();
}
};

DECLARE_WAYFIRE_PLUGIN(wf::per_output_plugin_t<wayfire_hide_cursor_plugin>);

}
51 changes: 36 additions & 15 deletions src/keycolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <wayfire/view-transform.hpp>
#include <wayfire/per-output-plugin.hpp>
#include <wayfire/signal-definitions.hpp>
#include <wayfire/matcher.hpp>


static const char *vertex_shader =
Expand Down Expand Up @@ -243,6 +244,14 @@ class wayfire_keycolor : public wf::plugin_interface_t
const std::string transformer_name = "keycolor";
std::map<wayfire_view, std::shared_ptr<wf_keycolor>> transformers;

wf::view_matcher_t enabled_for{"keycolor/enabled_for"};
wf::option_wrapper_t<std::string> enabled_for_option{"keycolor/enabled_for"};

bool should_enable_for(wayfire_view view)
{
return enabled_for.matches(view);
}

void add_transformer(wayfire_view view)
{
if (view->get_transformed_node()->get_transformer(transformer_name))
Expand All @@ -263,6 +272,23 @@ class wayfire_keycolor : public wf::plugin_interface_t
}
}

void update_view(wayfire_view view)
{
if (view->role == wf::VIEW_ROLE_DESKTOP_ENVIRONMENT)
{
pop_transformer(view);
return;
}

if (should_enable_for(view))
{
add_transformer(view);
} else
{
pop_transformer(view);
}
}

void remove_transformers()
{
for (auto& view : wf::get_core().get_all_views())
Expand Down Expand Up @@ -295,16 +321,19 @@ class wayfire_keycolor : public wf::plugin_interface_t

program_ref_count++;

wf::get_core().connect(&on_view_map);

for (auto& view : wf::get_core().get_all_views())
enabled_for_option.set_callback([=] ()
{
if (view->role == wf::VIEW_ROLE_DESKTOP_ENVIRONMENT)
for (auto& view : wf::get_core().get_all_views())
{
continue;
update_view(view);
}
});

add_transformer(view);
wf::get_core().connect(&on_view_map);

for (auto& view : wf::get_core().get_all_views())
{
update_view(view);
}
}

Expand All @@ -316,17 +345,9 @@ class wayfire_keycolor : public wf::plugin_interface_t
return;
}

if (view->role == wf::VIEW_ROLE_DESKTOP_ENVIRONMENT)
{
return;
}

idle_attach.run_once([=] ()
{
if (!view->get_transformed_node()->get_transformer(transformer_name))
{
add_transformer(view);
}
update_view(view);
});
};

Expand Down