Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open layer shell surfaces on wayland #66

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion showmethekey-gtk/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ cairo = dependency('cairo', required: true)
pango = dependency('pango', required: true)
xkbcommon = dependency('xkbcommon', required: true)
xkbregistry = dependency('xkbregistry', required: true)
gtk4_layer_shell = dependency('gtk4-layer-shell-0', required: true)
gtk_dependencies += [
gtk, libadw, x11, glib, json_glib, gio, cairo, pango, xkbcommon, xkbregistry
gtk, libadw, x11, glib, json_glib, gio, cairo, pango, xkbcommon, xkbregistry, gtk4_layer_shell
]
# For config.h.
gtk_include_directories += include_directories('../')
Expand Down
196 changes: 103 additions & 93 deletions showmethekey-gtk/smtk-app-win.ui
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<property name="hexpand">false</property>
<property name="halign">center</property>
<signal
name="notify::active"
handler="smtk_app_win_on_keys_win_switch_active"
object="SmtkAppWin"
swapped="yes" />
name="notify::active"
handler="smtk_app_win_on_keys_win_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
<child type="end">
Expand All @@ -42,7 +42,8 @@
</object>
</child>
<child>
<object class="AdwClamp">
<object class="GtkScrolledWindow">
<property name="vexpand">true</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
Expand All @@ -58,18 +59,19 @@
<object class="AdwActionRow">
<property name="use-underline">true</property>
<property name="title" translatable="yes">_Clickable</property>
<property name="subtitle" translatable="yes">Turning off will pass input event to other apps under the floating window.</property>
<property name="subtitle" translatable="yes">Turning off will pass input
event to other apps under the floating window.</property>
<property name="activatable-widget">clickable_switch</property>
<child>
<object class="GtkSwitch" id="clickable_switch">
<property name="valign">center</property>
<property name="sensitive">false</property>
<property name="active">true</property>
<signal
name="notify::active"
handler="smtk_app_win_on_clickable_switch_active"
object="SmtkAppWin"
swapped="yes" />
name="notify::active"
handler="smtk_app_win_on_clickable_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
Expand All @@ -78,18 +80,19 @@
<object class="AdwActionRow">
<property name="use-underline">true</property>
<property name="title" translatable="yes">_Pause</property>
<property name="subtitle" translatable="yes">Temporary hide input like password. Press both alt anywhere to toggle this.</property>
<property name="subtitle" translatable="yes">Temporary hide input like
password. Press both alt anywhere to toggle this.</property>
<property name="activatable-widget">pause_switch</property>
<child>
<object class="GtkSwitch" id="pause_switch">
<property name="valign">center</property>
<property name="sensitive">false</property>
<property name="active">false</property>
<signal
name="notify::active"
handler="smtk_app_win_on_pause_switch_active"
object="SmtkAppWin"
swapped="yes" />
name="notify::active"
handler="smtk_app_win_on_pause_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
Expand All @@ -105,10 +108,10 @@
<property name="valign">center</property>
<property name="active">true</property>
<signal
name="notify::active"
handler="smtk_app_win_on_shift_switch_active"
object="SmtkAppWin"
swapped="yes" />
name="notify::active"
handler="smtk_app_win_on_shift_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
Expand All @@ -117,17 +120,18 @@
<object class="AdwActionRow">
<property name="use-underline">true</property>
<property name="title" translatable="yes">Show _Keyboard Key</property>
<property name="subtitle" translatable="yes">Maybe some users don't want keyboard keys.</property>
<property name="subtitle" translatable="yes">Maybe some users don't want
keyboard keys.</property>
<property name="activatable-widget">keyboard_switch</property>
<child>
<object class="GtkSwitch" id="keyboard_switch">
<property name="valign">center</property>
<property name="active">true</property>
<signal
name="notify::active"
handler="smtk_app_win_on_keyboard_switch_active"
object="SmtkAppWin"
swapped="yes" />
<property name="valign">center</property>
<property name="active">true</property>
<signal
name="notify::active"
handler="smtk_app_win_on_keyboard_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
Expand All @@ -136,17 +140,18 @@
<object class="AdwActionRow">
<property name="use-underline">true</property>
<property name="title" translatable="yes">Show _Mouse Button</property>
<property name="subtitle" translatable="yes">Mouse buttons can be very annoying.</property>
<property name="subtitle" translatable="yes">Mouse buttons can be very
annoying.</property>
<property name="activatable-widget">mouse_switch</property>
<child>
<object class="GtkSwitch" id="mouse_switch">
<property name="valign">center</property>
<property name="active">true</property>
<signal
name="notify::active"
handler="smtk_app_win_on_mouse_switch_active"
object="SmtkAppWin"
swapped="yes" />
name="notify::active"
handler="smtk_app_win_on_mouse_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
Expand All @@ -155,44 +160,46 @@
<object class="AdwActionRow">
<property name="use-underline">true</property>
<property name="title" translatable="yes">Draw Keys _Border</property>
<property name="subtitle" translatable="yes">In case keys and key combos are hard to distinguish.</property>
<property name="subtitle" translatable="yes">In case keys and key combos are
hard to distinguish.</property>
<property name="activatable-widget">border_switch</property>
<child>
<object class="GtkSwitch" id="border_switch">
<property name="valign">center</property>
<property name="active">true</property>
<signal
name="notify::active"
handler="smtk_app_win_on_border_switch_active"
object="SmtkAppWin"
swapped="yes" />
name="notify::active"
handler="smtk_app_win_on_border_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="use-underline">true</property>
<property name="title" translatable="yes">Hide _Visible Keys</property>
<property name="subtitle" translatable="yes">Only show keys with modifiers.</property>
<property name="activatable-widget">hide_visible_switch</property>
<child>
<object class="GtkSwitch" id="hide_visible_switch">
<property name="valign">center</property>
<property name="active">false</property>
<signal
name="notify::active"
handler="smtk_app_win_on_hide_visible_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="use-underline">true</property>
<property name="title" translatable="yes">Hide _Visible Keys</property>
<property name="subtitle" translatable="yes">Only show keys with modifiers.</property>
<property name="activatable-widget">hide_visible_switch</property>
<child>
<object class="GtkSwitch" id="hide_visible_switch">
<property name="valign">center</property>
<property name="active">false</property>
<signal
name="notify::active"
handler="smtk_app_win_on_hide_visible_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
</child>
<child>
<object class="AdwComboRow" id="mode_selector">
<property name="title" translatable="yes">Display Mode</property>
<property name="subtitle" translatable="yes">Raw is Linux kernel's scancode and maybe not so useful.</property>
<property name="subtitle" translatable="yes">Raw is Linux kernel's scancode
and maybe not so useful.</property>
<!-- Must keep the same sequence with SmtkKeyMode. -->
<property name="selected">0</property>
<property name="model">
Expand All @@ -205,38 +212,40 @@
</object>
</property>
<signal
name="notify::selected"
handler="smtk_app_win_on_mode_selector_selected"
object="SmtkAppWin"
swapped="yes" />
name="notify::selected"
handler="smtk_app_win_on_mode_selector_selected"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
<child>
<object class="AdwComboRow" id="alignment_selector">
<property name="title" translatable="yes">Alignment Mode</property>
<property name="subtitle" translatable="yes">Some users prefer to display
keys in center.</property>
<!-- Must keep the same sequence with SmtkKeyAlignment. -->
<property name="selected">0</property>
<property name="model">
<object class="GtkStringList">
<items>
<item translatable="yes">End</item>
<item translatable="yes">Center</item>
</items>
</object>
</property>
<signal
name="notify::selected"
handler="smtk_app_win_on_alignment_selector_selected"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
<child>
<object class="AdwComboRow" id="alignment_selector">
<property name="title" translatable="yes">Alignment Mode</property>
<property name="subtitle" translatable="yes">Some users prefer to display keys in center.</property>
<!-- Must keep the same sequence with SmtkKeyAlignment. -->
<property name="selected">0</property>
<property name="model">
<object class="GtkStringList">
<items>
<item translatable="yes">End</item>
<item translatable="yes">Center</item>
</items>
</object>
</property>
<signal
name="notify::selected"
handler="smtk_app_win_on_alignment_selector_selected"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="use-underline">true</property>
<property name="title" translatable="yes">Timeout (ms)</property>
<property name="subtitle" translatable="yes">Clear keys if no new key after how many miliscconds. Set to 0 to keep all keys.</property>
<property name="subtitle" translatable="yes">Clear keys if no new key after
how many miliscconds. Set to 0 to keep all keys.</property>
<property name="activatable-widget">timeout_entry</property>
<child>
<object class="GtkSpinButton" id="timeout_entry">
Expand All @@ -245,10 +254,10 @@
<property name="digits">0</property>
<property name="text">0</property>
<signal
name="notify::value"
handler="smtk_app_win_on_timeout_value"
object="SmtkAppWin"
swapped="yes" />
name="notify::value"
handler="smtk_app_win_on_timeout_value"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
Expand Down Expand Up @@ -294,14 +303,15 @@
<object class="AdwComboRow" id="keymap_selector">
<property name="use-underline">true</property>
<property name="title" translatable="yes">Keymap</property>
<property name="subtitle" translatable="yes">Choose your keyboard layout and variant.</property>
<property name="subtitle" translatable="yes">Choose your keyboard layout and
variant.</property>
<!-- <property name="enable-search">true</property> -->
<property name="selected">0</property>
<signal
name="notify::selected"
handler="smtk_app_win_on_keymap_selector_selected"
object="SmtkAppWin"
swapped="yes" />
name="notify::selected"
handler="smtk_app_win_on_keymap_selector_selected"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
Expand All @@ -313,4 +323,4 @@
</object>
</property>
</template>
</interface>
</interface>
22 changes: 10 additions & 12 deletions showmethekey-gtk/smtk-keys-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#endif

#include "smtk.h"
#include "gtk4-layer-shell.h"
#include "smtk-keys-win.h"

struct _SmtkKeysWin {
Expand Down Expand Up @@ -334,8 +335,16 @@ static void smtk_keys_win_init(SmtkKeysWin *win)
// Don't know why but realize does not work.
g_signal_connect(GTK_WIDGET(win), "map",
G_CALLBACK(smtk_keys_win_on_map), NULL);
}

GtkWindow* gtk_window = GTK_WINDOW(win);
// Create a layer shell surface instead of a normal floating window
gtk_layer_init_for_window(gtk_window);
// Make the layer appear on top of normal windows
gtk_layer_set_layer(gtk_window, GTK_LAYER_SHELL_LAYER_TOP);
gtk_layer_set_anchor(gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, true);
gtk_layer_set_anchor(gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, true);
gtk_layer_set_anchor(gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, true);
Comment on lines +339 to +346
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this break desktops without layer shell? If the library don't check by itself, we may need to check here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it falls back to a floating window but i haven't checked

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has a gtk_layer_is_supported() function though so it's easy to check

}
static void smtk_keys_win_constructed(GObject *object)
{
// Seems we can only get constructor properties here.
Expand All @@ -344,16 +353,6 @@ static void smtk_keys_win_constructed(GObject *object)
win->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
adw_window_set_content(ADW_WINDOW(win), win->box);

// Allow user to choose position by drag this.
win->header_bar = adw_header_bar_new();
adw_header_bar_set_show_start_title_buttons(
ADW_HEADER_BAR(win->header_bar), false);
adw_header_bar_set_show_end_title_buttons(
ADW_HEADER_BAR(win->header_bar), false);
win->handle = adw_window_title_new(_("Clickable"), NULL);
adw_header_bar_set_title_widget(ADW_HEADER_BAR(win->header_bar),
win->handle);
gtk_box_append(GTK_BOX(win->box), win->header_bar);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally have no opinion about layer shell if it don't break other things, but if you insist to make myself unable to move my window, I cannot accept that. I am a GNOME lover.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem I can add it back but only when is a floating window because it doesn't work when it is a layer.
Sorry for removing that, i was kinda desperate to make this work properly on hyprland (make the window not tile and be automatically positioned at the bottom) so probably have somethings to fix.

win->emitter = smtk_keys_emitter_new(win->show_shift,
win->show_keyboard,
Expand Down Expand Up @@ -381,7 +380,6 @@ static void smtk_keys_win_constructed(GObject *object)
win->area = smtk_keys_area_new(win->mode, win->alignment,
win->draw_border, win->timeout);
gtk_box_append(GTK_BOX(win->box), win->area);

out:
G_OBJECT_CLASS(smtk_keys_win_parent_class)->constructed(object);
}
Expand Down