Fixed notifications list not scrolling when changing focus

This commit is contained in:
Erik Reider
2023-09-26 17:04:56 +02:00
parent 3069f7120d
commit 237310c627
2 changed files with 67 additions and 53 deletions

View File

@@ -20,89 +20,101 @@
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkScrolledWindow" id="scrolled_window"> <object class="GtkBox" id="notifications_box">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">False</property>
<property name="hscrollbar-policy">never</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkViewport" id="viewport"> <object class="GtkStack" id="stack">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="vexpand">True</property> <property name="transition-type">crossfade</property>
<property name="shadow-type">none</property>
<child> <child>
<object class="GtkStack" id="stack"> <object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">True</property>
<property name="transition-type">crossfade</property> <property name="hscrollbar-policy">never</property>
<child> <child>
<object class="GtkBox"> <object class="GtkViewport" id="viewport">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="orientation">vertical</property> <property name="shadow-type">none</property>
<property name="spacing">12</property>
<child> <child>
<object class="GtkImage"> <object class="GtkListBox" id="list_box">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="pixel-size">96</property> <property name="valign">end</property>
<property name="icon-name">preferences-system-notifications-symbolic</property> <property name="selection-mode">none</property>
<property name="use-fallback">True</property> <property name="activate-on-single-click">False</property>
<property name="icon_size">0</property> <style>
<class name="control-center-list"/>
</style>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child> </child>
<child> </object>
<object class="GtkLabel"> </child>
<property name="visible">True</property> </object>
<property name="can-focus">False</property> <packing>
<property name="label" translatable="yes">No Notifications</property> <property name="name">notifications-list</property>
</object> </packing>
<packing> </child>
<property name="expand">False</property> <child>
<property name="fill">True</property> <object class="GtkBox">
<property name="position">1</property> <property name="visible">True</property>
</packing> <property name="can-focus">False</property>
</child> <property name="halign">center</property>
<style> <property name="valign">center</property>
<class name="control-center-list-placeholder"/> <property name="hexpand">True</property>
</style> <property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixel-size">96</property>
<property name="icon-name">preferences-system-notifications-symbolic</property>
<property name="use-fallback">True</property>
<property name="icon_size">0</property>
</object> </object>
<packing> <packing>
<property name="name">notifications-placeholder</property> <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkListBox" id="list_box"> <object class="GtkLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="valign">end</property> <property name="label" translatable="yes">No Notifications</property>
<property name="selection-mode">none</property>
<property name="activate-on-single-click">False</property>
<style>
<class name="control-center-list"/>
</style>
</object> </object>
<packing> <packing>
<property name="name">notifications-list</property> <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<style>
<class name="control-center-list-placeholder"/>
</style>
</object> </object>
<packing>
<property name="name">notifications-placeholder</property>
<property name="position">1</property>
</packing>
</child> </child>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child> </child>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>

View File

@@ -2,6 +2,8 @@ namespace SwayNotificationCenter {
[GtkTemplate (ui = "/org/erikreider/sway-notification-center/controlCenter/controlCenter.ui")] [GtkTemplate (ui = "/org/erikreider/sway-notification-center/controlCenter/controlCenter.ui")]
public class ControlCenter : Gtk.ApplicationWindow { public class ControlCenter : Gtk.ApplicationWindow {
[GtkChild]
unowned Gtk.Box notifications_box;
[GtkChild] [GtkChild]
unowned Gtk.ScrolledWindow scrolled_window; unowned Gtk.ScrolledWindow scrolled_window;
[GtkChild] [GtkChild]
@@ -243,11 +245,11 @@ namespace SwayNotificationCenter {
if (w.length == 0) w = DEFAULT_WIDGETS; if (w.length == 0) w = DEFAULT_WIDGETS;
bool has_notification = false; bool has_notification = false;
foreach (string key in w) { foreach (string key in w) {
// Reposition the scrolled_window // Reposition the notifications_box
if (key == "notifications") { if (key == "notifications") {
has_notification = true; has_notification = true;
uint pos = box.get_children ().length (); uint pos = box.get_children ().length ();
box.reorder_child (scrolled_window, (int) (pos > 0 ? --pos : 0)); box.reorder_child (notifications_box, (int) (pos > 0 ? --pos : 0));
continue; continue;
} }
// Add the widget if it is valid // Add the widget if it is valid
@@ -261,7 +263,7 @@ namespace SwayNotificationCenter {
if (!has_notification) { if (!has_notification) {
warning ("Notification widget not included in \"widgets\" config. Using default bottom position"); warning ("Notification widget not included in \"widgets\" config. Using default bottom position");
uint pos = box.get_children ().length (); uint pos = box.get_children ().length ();
box.reorder_child (scrolled_window, (int) (pos > 0 ? --pos : 0)); box.reorder_child (notifications_box, (int) (pos > 0 ? --pos : 0));
} }
} }