Skip to content

Commit

Permalink
Fixed notifications list not scrolling when changing focus
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikReider committed Sep 26, 2023
1 parent 3069f71 commit 237310c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 53 deletions.
112 changes: 62 additions & 50 deletions src/controlCenter/controlCenter.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,89 +20,101 @@
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<object class="GtkBox" id="notifications_box">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hscrollbar-policy">never</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkViewport" id="viewport">
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="vexpand">True</property>
<property name="shadow-type">none</property>
<property name="transition-type">crossfade</property>
<child>
<object class="GtkStack" id="stack">
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="transition-type">crossfade</property>
<property name="can-focus">True</property>
<property name="hscrollbar-policy">never</property>
<child>
<object class="GtkBox">
<object class="GtkViewport" id="viewport">
<property name="visible">True</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="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>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<property name="shadow-type">none</property>
<child>
<object class="GtkLabel">
<object class="GtkListBox" id="list_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">No Notifications</property>
<property name="valign">end</property>
<property name="selection-mode">none</property>
<property name="activate-on-single-click">False</property>
<style>
<class name="control-center-list"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<style>
<class name="control-center-list-placeholder"/>
</style>
</object>
</child>
</object>
<packing>
<property name="name">notifications-list</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</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="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>
<packing>
<property name="name">notifications-placeholder</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkListBox" id="list_box">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">end</property>
<property name="selection-mode">none</property>
<property name="activate-on-single-click">False</property>
<style>
<class name="control-center-list"/>
</style>
<property name="label" translatable="yes">No Notifications</property>
</object>
<packing>
<property name="name">notifications-list</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<style>
<class name="control-center-list-placeholder"/>
</style>
</object>
<packing>
<property name="name">notifications-placeholder</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
Expand Down
8 changes: 5 additions & 3 deletions src/controlCenter/controlCenter.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace SwayNotificationCenter {
[GtkTemplate (ui = "/org/erikreider/sway-notification-center/controlCenter/controlCenter.ui")]
public class ControlCenter : Gtk.ApplicationWindow {

[GtkChild]
unowned Gtk.Box notifications_box;
[GtkChild]
unowned Gtk.ScrolledWindow scrolled_window;
[GtkChild]
Expand Down Expand Up @@ -243,11 +245,11 @@ namespace SwayNotificationCenter {
if (w.length == 0) w = DEFAULT_WIDGETS;
bool has_notification = false;
foreach (string key in w) {
// Reposition the scrolled_window
// Reposition the notifications_box
if (key == "notifications") {
has_notification = true;
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;
}
// Add the widget if it is valid
Expand All @@ -261,7 +263,7 @@ namespace SwayNotificationCenter {
if (!has_notification) {
warning ("Notification widget not included in \"widgets\" config. Using default bottom position");
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));
}
}

Expand Down

0 comments on commit 237310c

Please sign in to comment.