diff --git a/lib/IndicatorManager.vala b/lib/IndicatorManager.vala index 0654952b..54e262bd 100644 --- a/lib/IndicatorManager.vala +++ b/lib/IndicatorManager.vala @@ -143,6 +143,7 @@ public class Wingpanel.IndicatorManager : GLib.Object { } private void load (string path) { + warning ("LOAD: %s", path); if (!Module.supported ()) { error ("Wingpanel is not supported by this system!"); } @@ -172,6 +173,7 @@ public class Wingpanel.IndicatorManager : GLib.Object { void* function; if (!module.symbol ("get_indicator", out function)) { + warning ("SYMBOL NOT FOUND"); return; } @@ -186,9 +188,10 @@ public class Wingpanel.IndicatorManager : GLib.Object { if (indicator == null) { debug ("Unknown plugin type for %s or indicator is hidden on this server!", path); - + warning ("INDICATOR IS NULL"); return; } + warning ("REGISTER"); module.make_resident (); register_indicator (path, indicator); @@ -327,7 +330,7 @@ public class Wingpanel.IndicatorManager : GLib.Object { * @param indicator The indicator. */ public void register_indicator (string path, Wingpanel.Indicator indicator) { - debug ("%s registered", indicator.code_name); + warning ("%s registered", indicator.code_name); var deregister_map = new Gee.HashMap (); indicators.@foreach ((entry) => { @@ -347,6 +350,7 @@ public class Wingpanel.IndicatorManager : GLib.Object { indicators.@set (path, indicator); indicator_added (indicator); + warning ("INDICATOR ADDED"); } /** diff --git a/lib/Widgets/Switch.vala b/lib/Widgets/Switch.vala deleted file mode 100644 index 341e3eda..00000000 --- a/lib/Widgets/Switch.vala +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2011-2018 elementary, Inc. (https://elementary.io) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - */ - -[Version (deprecated = true, deprecated_since = "3.0.0", replacement = "Granite.SwitchModelButton")] -public class Wingpanel.Widgets.Switch : Gtk.Bin { - public bool active { get; set; } - public string caption { owned get; set; } - - private Gtk.Label button_label; - private Gtk.Switch button_switch; - - public Switch (string caption, bool active = false) { - Object (caption: caption, active: active); - } - - public Switch.with_mnemonic (string caption, bool active = false) { - Object (caption: caption, active: active); - button_label.set_text_with_mnemonic (caption); - button_label.set_mnemonic_widget (this); - } - - construct { - button_switch = new Gtk.Switch (); - button_switch.active = active; - button_switch.halign = Gtk.Align.END; - button_switch.hexpand = true; - button_switch.valign = Gtk.Align.CENTER; - - button_label = new Gtk.Label (null); - button_label.halign = Gtk.Align.START; - - var grid = new Gtk.Grid (); - grid.column_spacing = 12; - grid.attach (button_label, 0, 0); - grid.attach (button_switch, 1, 0); - - var modelbutton = new Gtk.ModelButton (); - modelbutton.get_child ().destroy (); - modelbutton.add (grid); - - add (modelbutton); - - modelbutton.button_release_event.connect (() => { - toggle_switch (); - // Stop modelbutton from closing the popover - return Gdk.EVENT_STOP; - }); - - bind_property ("active", button_switch, "active", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.BIDIRECTIONAL); - bind_property ("caption", button_label, "label", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.BIDIRECTIONAL); - } - - public new Gtk.Label get_label () { - return button_label; - } - - public Gtk.Switch get_switch () { - return button_switch; - } - - public void toggle_switch () { - button_switch.activate (); - } -} diff --git a/lib/meson.build b/lib/meson.build index 93e2f384..337635e9 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -1,4 +1,4 @@ -indicators_dir = join_paths(get_option('prefix'), get_option('libdir'), 'wingpanel') +indicators_dir = join_paths(get_option('prefix'), get_option('libdir'), 'wingpanel-4') config_vapi = meson.get_compiler('vala').find_library('config', dirs: meson.current_source_dir()) @@ -19,13 +19,11 @@ libwingpanel_deps = [ gtk_dep, ] -libwingpanel_lib = library('wingpanel', +libwingpanel_lib = library('wingpanel-4', 'Indicator.vala', 'IndicatorManager.vala', - 'Widgets/Container.vala', - 'Widgets/OverlayIcon.vala', - 'Widgets/Separator.vala', - 'Widgets/Switch.vala', + # 'Widgets/Container.vala', + # 'Widgets/OverlayIcon.vala', config_header, dependencies: [libwingpanel_deps, config_vapi], vala_header: 'wingpanel.h', @@ -37,7 +35,7 @@ libwingpanel_lib = library('wingpanel', pkg.generate( libwingpanel_lib, filebase: 'wingpanel', - name: 'Wingpanel', + name: 'Wingpanel-4', description: 'Wingpanel Indicators API', version: meson.project_version(), subdirs: 'wingpanel', diff --git a/lib/wingpanel.deps b/lib/wingpanel.deps index c66f52c0..94b35e5e 100644 --- a/lib/wingpanel.deps +++ b/lib/wingpanel.deps @@ -1,4 +1,4 @@ glib-2.0 gee-0.8 gmodule-2.0 -gtk+-3.0 +gtk4 diff --git a/meson.build b/meson.build index 8d4d5e7f..42b76fc7 100644 --- a/meson.build +++ b/meson.build @@ -28,13 +28,13 @@ glib_dep = dependency('glib-2.0', version: '>=2.32') gio_dep = dependency('gio-2.0') gio_unix_dep = dependency('gio-unix-2.0') gmodule_dep = dependency('gmodule-2.0') -gdk_wl_dep = dependency('gdk-wayland-3.0') +gdk_wl_dep = dependency('gtk4-wayland') # GDK X11 dep is for detecting whether we're on Wayland or not ONLY, we don't actually have # a hard X11 dependency here -gdk_x11_dep = dependency('gdk-x11-3.0') -gtk_dep = dependency('gtk+-3.0', version: '>=3.10') +# gdk_x11_dep = dependency('gdk-x11-3.0') +gtk_dep = dependency('gtk4') gee_dep = dependency('gee-0.8') -granite_dep = dependency('granite', version: '>=5.4.0') +granite_dep = dependency('granite-7') posix_dep = meson.get_compiler('vala').find_library('posix') wl_client_dep = dependency('wayland-client') @@ -46,6 +46,7 @@ subdir('src') subdir('wingpanel-interface') if get_option('example') subdir('sample') + subdir('sample copy') endif subdir('po') vapigen = find_program('vapigen', required: false) diff --git a/sample/SampleIndicator.vala b/sample/SampleIndicator.vala index 9bd042a1..9f61551e 100644 --- a/sample/SampleIndicator.vala +++ b/sample/SampleIndicator.vala @@ -47,16 +47,22 @@ public class Sample.Indicator : Wingpanel.Indicator { /* Create a new composited icon */ display_widget = new Gtk.Overlay (); - display_widget.add (main_image); + display_widget.set_child (main_image); display_widget.add_overlay (overlay_image); + var scroll = new Gtk.EventControllerScroll (NONE); + main_image.add_controller (scroll); + scroll.scroll.connect (() => { + warning ("SCROLL"); + }); + var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) { margin_top = 3, margin_bottom = 3 }; - var hide_button = new Gtk.ModelButton (); - hide_button.text = _("Hide me!"); + var hide_button = new Gtk.Button (); + hide_button.label = _("Hide me!"); var compositing_switch = new Granite.SwitchModelButton (_("Composited Icon")); diff --git a/src/Application.vala b/src/Application.vala index 25e65f95..bd5cb892 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -117,7 +117,7 @@ public class Wingpanel.Application : Gtk.Application { base.startup (); panel_window = new PanelWindow (this); - panel_window.show_all (); + panel_window.present (); register_actions (); } diff --git a/src/PanelWindow.vala b/src/PanelWindow.vala index 9eca83c4..449a6b7e 100644 --- a/src/PanelWindow.vala +++ b/src/PanelWindow.vala @@ -22,7 +22,7 @@ public class Wingpanel.PanelWindow : Gtk.Window { private Widgets.Panel panel; private Gtk.EventControllerKey key_controller; // For keeping in memory - private Gtk.GestureMultiPress gesture_controller; // For keeping in memory + private Gtk.GestureClick gesture_controller; // For keeping in memory private Gtk.Revealer revealer; private int monitor_number; private int monitor_width; @@ -38,24 +38,20 @@ public class Wingpanel.PanelWindow : Gtk.Window { public PanelWindow (Gtk.Application application) { Object ( application: application, - app_paintable: true, decorated: false, resizable: false, - skip_pager_hint: true, - skip_taskbar_hint: true, - type_hint: Gdk.WindowTypeHint.DOCK, vexpand: false ); - monitor_number = screen.get_primary_monitor (); + // monitor_number = screen.get_primary_monitor (); var app_provider = new Gtk.CssProvider (); app_provider.load_from_resource ("io/elementary/wingpanel/Application.css"); - Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), app_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), app_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - this.screen.size_changed.connect (update_panel_dimensions); - this.screen.monitors_changed.connect (update_panel_dimensions); - this.screen_changed.connect (update_visual); + // this.screen.size_changed.connect (update_panel_dimensions); + // this.screen.monitors_changed.connect (update_panel_dimensions); + // this.screen_changed.connect (update_visual); update_visual (); @@ -83,10 +79,10 @@ public class Wingpanel.PanelWindow : Gtk.Window { child = revealer; - key_controller = new Gtk.EventControllerKey (this); + key_controller = new Gtk.EventControllerKey (); key_controller.key_pressed.connect (on_key_pressed); - gesture_controller = new Gtk.GestureMultiPress (this) { + gesture_controller = new Gtk.GestureClick () { propagation_phase = CAPTURE }; @@ -96,7 +92,7 @@ public class Wingpanel.PanelWindow : Gtk.Window { } }); - panel.size_allocate.connect (update_panel_dimensions); + panel.map.connect (update_panel_dimensions); } private void on_realize () { @@ -111,47 +107,46 @@ public class Wingpanel.PanelWindow : Gtk.Window { revealer.transition_type = SLIDE_DOWN; revealer.reveal_child = true; - // We have to wrap in Idle otherwise the Meta.Window of the WaylandSurface in Gala is still null - Idle.add_once (init_wl); + init_wl (); } private void update_panel_dimensions () { panel_height = panel.get_allocated_height (); - monitor_number = screen.get_primary_monitor (); + // monitor_number = screen.get_primary_monitor (); Gdk.Rectangle monitor_dimensions; if (Utils.is_wayland ()) { // We just use our monitor because Gala makes sure we are always on the primary one - monitor_dimensions = get_display ().get_monitor_at_window (get_window ()).get_geometry (); + monitor_dimensions = get_display ().get_monitor_at_surface (get_surface ()).get_geometry (); monitor_dimensions.width /= get_scale_factor (); monitor_dimensions.height /= get_scale_factor (); monitor_dimensions.x /= get_scale_factor (); monitor_dimensions.y /= get_scale_factor (); - } else { - monitor_dimensions = get_display ().get_primary_monitor ().get_geometry (); - } - monitor_width = monitor_dimensions.width; - monitor_height = monitor_dimensions.height; + monitor_width = monitor_dimensions.width; + monitor_height = monitor_dimensions.height; - this.set_size_request (monitor_width, (popover_manager.current_indicator != null ? monitor_height : -1)); + this.set_size_request (monitor_width, -1); - monitor_x = monitor_dimensions.x; - monitor_y = monitor_dimensions.y; + monitor_x = monitor_dimensions.x; + monitor_y = monitor_dimensions.y; + } else { + // monitor_dimensions = get_display ().get_primary_monitor ().get_geometry (); + } - move (monitor_x, monitor_y); + // move (monitor_x, monitor_y); - update_struts (); + // update_struts (); } private void update_visual () { - var visual = this.screen.get_rgba_visual (); + // // var visual = this.screen.get_rgba_visual (); - if (visual == null) { - warning ("Compositing not available, things will Look Bad (TM)"); - } else { - this.set_visual (visual); - } + // if (visual == null) { + // warning ("Compositing not available, things will Look Bad (TM)"); + // } else { + // // this.set_visual (visual); + // } } private bool on_key_pressed (uint keyval, uint keycode, Gdk.ModifierType state) { @@ -162,66 +157,72 @@ public class Wingpanel.PanelWindow : Gtk.Window { return Gdk.EVENT_PROPAGATE; } - private void update_struts () { - if (!this.get_realized () || panel == null) { - return; - } - - /** - * https://specifications.freedesktop.org/wm-spec/wm-spec-1.5.html#NETWMSTRUT - * The _NET_WM_STRUCT_PARTICAL specification does not allow to reserve space for arbitrary rectangles - * on the screen. Instead it only allows to reserve space at the borders of screen. - * As for multi-monitor layouts the wingpanel can be at the within the screen (and not at the border) - * this makes it impossible to reserve the correct space for all possible multi-monitor layouts. - * Fortunately for up to 3 monitors there is always a possiblity to reserve the right space by also - * using the struct-left and struct-right cardinals. - */ - - var display = get_display (); - var n_monitors = display.get_n_monitors (); - int screen_width = 0; - bool no_monitor_left = true; - bool no_monitor_right = true; - bool no_monitor_above = true; - for (var i = 0; i < n_monitors; i++) { - var rect = display.get_monitor (i).get_geometry (); - screen_width = int.max (screen_width, rect.x + rect.width); - if (i == monitor_number) { - continue; - } - - var is_left = rect.x + rect.width <= monitor_x; - var is_right = rect.x >= monitor_x + monitor_width; - var is_above = rect.y + rect.height <= monitor_y; - var is_below = rect.y >= monitor_y + panel_height; - no_monitor_left &= !is_left || is_above || is_below; - no_monitor_right &= !is_right || is_above || is_below; - no_monitor_above &= !is_above || is_left || is_right; - } + // private void update_struts () { + // if (!this.get_realized () || panel == null) { + // return; + // } + + // /** + // * https://specifications.freedesktop.org/wm-spec/wm-spec-1.5.html#NETWMSTRUT + // * The _NET_WM_STRUCT_PARTICAL specification does not allow to reserve space for arbitrary rectangles + // * on the screen. Instead it only allows to reserve space at the borders of screen. + // * As for multi-monitor layouts the wingpanel can be at the within the screen (and not at the border) + // * this makes it impossible to reserve the correct space for all possible multi-monitor layouts. + // * Fortunately for up to 3 monitors there is always a possiblity to reserve the right space by also + // * using the struct-left and struct-right cardinals. + // */ + + // var display = get_display (); + // var n_monitors = display.get_n_monitors (); + // int screen_width = 0; + // bool no_monitor_left = true; + // bool no_monitor_right = true; + // bool no_monitor_above = true; + // for (var i = 0; i < n_monitors; i++) { + // var rect = display.get_monitor (i).get_geometry (); + // screen_width = int.max (screen_width, rect.x + rect.width); + // if (i == monitor_number) { + // continue; + // } + + // var is_left = rect.x + rect.width <= monitor_x; + // var is_right = rect.x >= monitor_x + monitor_width; + // var is_above = rect.y + rect.height <= monitor_y; + // var is_below = rect.y >= monitor_y + panel_height; + // no_monitor_left &= !is_left || is_above || is_below; + // no_monitor_right &= !is_right || is_above || is_below; + // no_monitor_above &= !is_above || is_left || is_right; + // } + + // long struts[12] = { 0 }; + // var scale_factor = this.get_scale_factor (); + // if (no_monitor_left) { + // struts [0] = (monitor_x + monitor_width) * scale_factor; + // struts [4] = monitor_y * scale_factor; + // struts [5] = (monitor_y + panel_height) * scale_factor - 1; + // } else if (no_monitor_right) { + // struts [1] = (screen_width - monitor_x) * scale_factor; + // struts [6] = monitor_y * scale_factor; + // struts [7] = (monitor_y + panel_height) * scale_factor - 1; + // } else if (no_monitor_above) { + // struts [2] = (monitor_y + panel_height) * scale_factor; + // struts [8] = monitor_x * scale_factor; + // struts [9] = (monitor_x + monitor_width) * scale_factor - 1; + // } else { + // warning ("Unable to set struts, because Wingpanel is not at the edge of the Gdk.Screen area."); + // } + + // Gdk.property_change (this.get_window (), Gdk.Atom.intern ("_NET_WM_STRUT_PARTIAL", false), + // Gdk.Atom.intern ("CARDINAL", false), 32, Gdk.PropMode.REPLACE, (uint8[])struts, 12); + // } - long struts[12] = { 0 }; - var scale_factor = this.get_scale_factor (); - if (no_monitor_left) { - struts [0] = (monitor_x + monitor_width) * scale_factor; - struts [4] = monitor_y * scale_factor; - struts [5] = (monitor_y + panel_height) * scale_factor - 1; - } else if (no_monitor_right) { - struts [1] = (screen_width - monitor_x) * scale_factor; - struts [6] = monitor_y * scale_factor; - struts [7] = (monitor_y + panel_height) * scale_factor - 1; - } else if (no_monitor_above) { - struts [2] = (monitor_y + panel_height) * scale_factor; - struts [8] = monitor_x * scale_factor; - struts [9] = (monitor_x + monitor_width) * scale_factor - 1; - } else { - warning ("Unable to set struts, because Wingpanel is not at the edge of the Gdk.Screen area."); + public void set_expanded (bool expand) { + return; + // This is a workaround for X11 + if (Utils.is_wayland ()) { + return; } - Gdk.property_change (this.get_window (), Gdk.Atom.intern ("_NET_WM_STRUT_PARTIAL", false), - Gdk.Atom.intern ("CARDINAL", false), 32, Gdk.PropMode.REPLACE, (uint8[])struts, 12); - } - - public void set_expanded (bool expand) { if (expand && !this.expanded) { Services.BackgroundManager.get_default ().remember_window (); @@ -232,7 +233,7 @@ public class Wingpanel.PanelWindow : Gtk.Window { this.expanded = false; this.set_size_request (monitor_width, -1); - this.resize (monitor_width, 1); + // this.resize (monitor_width, 1); } } @@ -247,9 +248,9 @@ public class Wingpanel.PanelWindow : Gtk.Window { public void registry_handle_global (Wl.Registry wl_registry, uint32 name, string @interface, uint32 version) { if (@interface == "io_elementary_pantheon_shell_v1") { desktop_shell = wl_registry.bind (name, ref Pantheon.Desktop.Shell.iface, uint32.min (version, 1)); - unowned var window = get_window (); - if (window is Gdk.Wayland.Window) { - unowned var wl_surface = ((Gdk.Wayland.Window) window).get_wl_surface (); + unowned var window = get_surface (); + if (window is Gdk.Wayland.Surface) { + unowned var wl_surface = ((Gdk.Wayland.Surface) window).get_wl_surface (); desktop_panel = desktop_shell.get_panel (wl_surface); desktop_panel.set_anchor (TOP); desktop_panel.set_hide_mode (NEVER); diff --git a/src/Services/PopoverManager.vala b/src/Services/PopoverManager.vala index a690cf5a..adc7af45 100644 --- a/src/Services/PopoverManager.vala +++ b/src/Services/PopoverManager.vala @@ -50,18 +50,18 @@ public class Wingpanel.Services.PopoverManager : Object { _current_indicator = value; } + popover.unparent (); + if (_current_indicator != null) { popover.set_content (_current_indicator.indicator_widget); - popover.relative_to = _current_indicator; + popover.set_parent (_current_indicator); update_has_tooltip (_current_indicator.display_widget, false); - owner.set_expanded (true); - make_modal (popover, true); owner.present (); + popover.position = BOTTOM; popover.popup (); - popover.show_all (); _current_indicator.base_indicator.opened (); } else { - update_has_tooltip (((Wingpanel.Widgets.IndicatorEntry)popover.get_relative_to ()).display_widget); + update_has_tooltip (((Wingpanel.Widgets.IndicatorEntry)popover.parent).display_widget); popover.popdown (); } } @@ -73,77 +73,7 @@ public class Wingpanel.Services.PopoverManager : Object { this.owner = owner; popover = new Wingpanel.Widgets.IndicatorPopover (); - - popover.leave_notify_event.connect ((e) => { - Gtk.Allocation allocation; - popover.get_allocation (out allocation); - - if (e.mode != Gdk.CrossingMode.NORMAL && e.subwindow == null) { - current_indicator = null; - } - - return Gdk.EVENT_PROPAGATE; - }); - - popover.closed.connect (() => { - make_modal (popover, false); - }); - popover.unmap.connect (() => { - if (!grabbed) { - owner.set_expanded (false); - } - }); - - owner.focus_out_event.connect ((e) => { - if (mousing) { - return Gdk.EVENT_PROPAGATE; - } - - if (current_indicator != null && e.window == null) { - current_indicator = null; - } - - return Gdk.EVENT_PROPAGATE; - }); - - owner.button_press_event.connect ((w, e) => { - // "owner" is the invisible window that fills the screen when an indicator is open, if the event didn't hit - // that window directly, then it was probably in the popover, so propagate it. - if (e.window != owner.get_window ()) { - return Gdk.EVENT_PROPAGATE; - } - - Gtk.Allocation allocation; - popover.get_allocation (out allocation); - - Gtk.Allocation indicator_allocation; - current_indicator.get_allocation (out indicator_allocation); - - Gtk.Allocation container_allocation; - current_indicator.get_parent ().get_allocation (out container_allocation); - - var wingpanel_width = owner.get_allocated_width (); - - allocation.x += indicator_allocation.x + - container_allocation.x - - ((allocation.width - indicator_allocation.width) / 2); - - if (allocation.x < 0) { - allocation.x = 0; - } - - if (allocation.x + allocation.width > wingpanel_width) { - allocation.x = wingpanel_width - allocation.width; - } - - if ((e.x < allocation.x || e.x > allocation.x + allocation.width) || (e.y < allocation.y || e.y > allocation.y + allocation.height)) { - current_indicator = null; - } - - return Gdk.EVENT_STOP; - }); - - owner.add_events (Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.BUTTON_PRESS_MASK); + popover.closed.connect (() => current_indicator = null); } public void set_popover_visible (string code_name, bool visible) { @@ -174,23 +104,6 @@ public class Wingpanel.Services.PopoverManager : Object { } } - private void make_modal (Gtk.Popover? pop, bool modal = true) { - if (pop == null || pop.get_window () == null || mousing) { - return; - } - - if (modal && !grabbed) { - grabbed = true; - Gtk.grab_add (owner); - owner.set_focus (null); - pop.grab_focus (); - } else if (!modal && grabbed) { - grabbed = false; - Gtk.grab_remove (owner); - owner.grab_focus (); - } - } - public void close () { if (current_indicator != null) { current_indicator = null; @@ -210,24 +123,6 @@ public class Wingpanel.Services.PopoverManager : Object { registered_indicators.set (widg.base_indicator.code_name, widg); - widg.enter_notify_event.connect ((w, e) => { - if (mousing) { - return Gdk.EVENT_PROPAGATE; - } - - if (grabbed) { - if (!get_visible (widg) && e.mode != Gdk.CrossingMode.TOUCH_BEGIN) { - mousing = true; - current_indicator = widg; - mousing = false; - } - - return Gdk.EVENT_STOP; - } - - return Gdk.EVENT_PROPAGATE; - }); - widg.notify["visible"].connect (() => { if (mousing || grabbed) { return; diff --git a/src/Utils.vala b/src/Utils.vala index de6805de..27eb9d3b 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -19,6 +19,6 @@ namespace Wingpanel.Utils { public static bool is_wayland () { - return !(Gdk.Display.get_default () is Gdk.X11.Display); + return Gdk.Display.get_default () is Gdk.Wayland.Display; } } diff --git a/src/Widgets/IndicatorEntry.vala b/src/Widgets/IndicatorEntry.vala index 9c020a4f..f8c9f7a1 100644 --- a/src/Widgets/IndicatorEntry.vala +++ b/src/Widgets/IndicatorEntry.vala @@ -17,7 +17,7 @@ * Boston, MA 02110-1301 USA. */ -public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { +public class Wingpanel.Widgets.IndicatorEntry : Gtk.Box { public Indicator base_indicator { get; construct; } public Services.PopoverManager popover_manager { get; construct; } @@ -45,7 +45,6 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { } construct { - can_focus = false; display_widget = base_indicator.get_display_widget (); halign = Gtk.Align.START; name = base_indicator.code_name + "/entry"; @@ -55,12 +54,14 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { return; } - revealer = new Gtk.Revealer (); - revealer.add (display_widget); + revealer = new Gtk.Revealer () { + child = display_widget + }; - add (revealer); + append (revealer); if (base_indicator.visible) { + warning ("REGISTER IN ENTRY"); popover_manager.register_indicator (this); } @@ -88,36 +89,19 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { } }); - add_events (Gdk.EventMask.SCROLL_MASK); - add_events (Gdk.EventMask.SMOOTH_SCROLL_MASK); - - scroll_event.connect ((e) => { - display_widget.scroll_event (e); - - return Gdk.EVENT_PROPAGATE; + var gesture_press = new Gtk.GestureClick (); + gesture_press.pressed.connect ((n_press) => { + popover_manager.current_indicator = this; }); + add_controller (gesture_press); - touch_event.connect ((e) => { - if (e.type == Gdk.EventType.TOUCH_BEGIN) { + var motion_controller = new Gtk.EventControllerMotion (); + motion_controller.enter.connect (() => { + if (popover_manager.current_indicator != null && popover_manager.current_indicator != this) { popover_manager.current_indicator = this; - return Gdk.EVENT_STOP; } - - return Gdk.EVENT_PROPAGATE; - }); - - button_press_event.connect ((e) => { - if ((e.button == Gdk.BUTTON_PRIMARY || e.button == Gdk.BUTTON_SECONDARY) - && e.type == Gdk.EventType.BUTTON_PRESS) { - popover_manager.current_indicator = this; - return Gdk.EVENT_STOP; - } - - /* Call button press on the indicator display widget */ - display_widget.button_press_event (e); - - return Gdk.EVENT_STOP; }); + add_controller (motion_controller); set_reveal (base_indicator.visible); } diff --git a/src/Widgets/IndicatorMenuBar.vala b/src/Widgets/IndicatorMenuBar.vala index e0f73505..f3b4bb61 100644 --- a/src/Widgets/IndicatorMenuBar.vala +++ b/src/Widgets/IndicatorMenuBar.vala @@ -17,7 +17,7 @@ * Boston, MA 02110-1301 USA. */ -public class Wingpanel.Widgets.IndicatorMenuBar : Gtk.MenuBar { +public class Wingpanel.Widgets.IndicatorMenuBar : Gtk.Box { private Gee.List sorted_items; private Services.IndicatorSorter sorter = new Services.IndicatorSorter (); @@ -34,30 +34,29 @@ public class Wingpanel.Widgets.IndicatorMenuBar : Gtk.MenuBar { } if (item.base_indicator.visible) { - var index = 0; + Gtk.Widget? previous = null; foreach (var i in sorted_items) { if (i == item) { break; } if (i.base_indicator.visible) { - index++; + previous = i; } } if (item.get_parent () != this) { - this.insert (item, index); + insert_child_after (item, previous); } } } - public override void remove (Gtk.Widget widget) { - var indicator_widget = widget as IndicatorEntry; - - if (indicator_widget != null) { - sorted_items.remove (indicator_widget); + public void remove_indicator (Indicator indicator) { + foreach (var entry in sorted_items) { + if (entry.base_indicator == indicator) { + sorted_items.remove (entry); + remove (entry); + } } - - base.remove (widget); } } diff --git a/src/Widgets/IndicatorPopover.vala b/src/Widgets/IndicatorPopover.vala index 989b7608..f7c2ef1a 100644 --- a/src/Widgets/IndicatorPopover.vala +++ b/src/Widgets/IndicatorPopover.vala @@ -24,7 +24,7 @@ public class Wingpanel.Widgets.IndicatorPopover : Gtk.Popover { construct { width_request = 256; - modal = false; + autohide = true; name = name + "/popover"; position = Gtk.PositionType.BOTTOM; @@ -33,7 +33,7 @@ public class Wingpanel.Widgets.IndicatorPopover : Gtk.Popover { margin_bottom = 3 }; - add (container); + child = container; } public void set_content (Gtk.Widget? content) { @@ -47,7 +47,7 @@ public class Wingpanel.Widgets.IndicatorPopover : Gtk.Popover { } if (content != null) { - container.add (content); + container.append (content); widget = content; } } diff --git a/src/Widgets/Panel.vala b/src/Widgets/Panel.vala index 9c03adab..11829a5c 100644 --- a/src/Widgets/Panel.vala +++ b/src/Widgets/Panel.vala @@ -17,12 +17,12 @@ * Boston, MA 02110-1301 USA. */ -public class Wingpanel.Widgets.Panel : Gtk.EventBox { +public class Wingpanel.Widgets.Panel : Gtk.Widget { public Services.PopoverManager popover_manager { get; construct; } private IndicatorMenuBar right_menubar; - private Gtk.MenuBar left_menubar; - private Gtk.MenuBar center_menubar; + private IndicatorMenuBar left_menubar; + private IndicatorMenuBar center_menubar; private unowned Gtk.StyleContext style_context; private Gtk.CssProvider? style_provider = null; @@ -36,31 +36,28 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { } construct { + layout_manager = new Gtk.BinLayout (); height_request = 30; hexpand = true; vexpand = true; valign = Gtk.Align.START; - left_menubar = new Gtk.MenuBar () { - can_focus = true, + left_menubar = new IndicatorMenuBar () { halign = Gtk.Align.START }; - center_menubar = new Gtk.MenuBar () { - can_focus = true - }; + center_menubar = new IndicatorMenuBar ();; right_menubar = new IndicatorMenuBar () { - can_focus = true, halign = Gtk.Align.END }; - var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - box.pack_start (left_menubar); + var box = new Gtk.CenterBox (); + box.start_widget = left_menubar; box.set_center_widget (center_menubar); - box.pack_end (right_menubar); + box.set_end_widget (right_menubar); - add (box); + box.set_parent (this); unowned IndicatorManager indicator_manager = IndicatorManager.get_default (); indicator_manager.indicator_added.connect (add_indicator); @@ -77,38 +74,6 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { Services.BackgroundManager.get_default ().background_state_changed.connect (update_background); } - public override bool button_press_event (Gdk.EventButton event) { - if (event.button != Gdk.BUTTON_PRIMARY) { - return Gdk.EVENT_PROPAGATE; - } - - var window = get_window (); - if (window == null) { - return Gdk.EVENT_PROPAGATE; - } - - // Grabbing with touchscreen on X does not work unfortunately - if (event.device.get_source () == Gdk.InputSource.TOUCHSCREEN) { - return Gdk.EVENT_PROPAGATE; - } - - uint32 time = event.time; - - window.get_display ().get_default_seat ().ungrab (); - - Gdk.ModifierType state; - event.get_state (out state); - - popover_manager.close (); - - var scale_factor = this.get_scale_factor (); - var x = (int)event.x_root * scale_factor; - var y = (int)event.y_root * scale_factor; - - var background_manager = Services.BackgroundManager.get_default (); - return background_manager.begin_grab_focused_window (x, y, (int)event.button, time, state); - } - public void cycle (bool forward) { var current = popover_manager.current_indicator; if (current == null) { @@ -117,9 +82,9 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { IndicatorEntry? sibling; if (forward) { - sibling = get_next_sibling (current); + sibling = get_next_indicator (current); } else { - sibling = get_previous_sibling (current); + sibling = get_previous_indicator (current); } if (sibling != null) { @@ -127,112 +92,38 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { } } - private IndicatorEntry? get_next_sibling (IndicatorEntry current) { - IndicatorEntry? sibling = null; + private IndicatorEntry? get_next_indicator (IndicatorEntry current) { + Gtk.Widget? sibling = current.get_next_sibling (); + + if (sibling != null) { + return (IndicatorEntry) sibling; + } switch (current.base_indicator.code_name) { case Indicator.APP_LAUNCHER: - var children = left_menubar.get_children (); - int index = children.index (current); - if (index == -1) { - break; - } else if (index < children.length () - 1) { // Has more than one indicator in the left menubar - sibling = children.nth_data (index + 1) as IndicatorEntry; - } else { // No more indicators on the left - var center_children = center_menubar.get_children (); - if (center_children.length () > 0) { - sibling = center_children.first ().data as IndicatorEntry; - } - } - - break; + return (IndicatorEntry) center_menubar.get_last_child (); case Indicator.DATETIME: - var children = center_menubar.get_children (); - int index = children.index (current); - if (index == -1) { - break; - } else if (index < children.length () - 1) { // Has more than one indicator in the center menubar - sibling = children.nth_data (index + 1) as IndicatorEntry; - } else { // No more indicators on the center - var right_children = right_menubar.get_children (); - if (right_children.length () > 0) { - sibling = right_children.first ().data as IndicatorEntry; - } - } - - break; + return (IndicatorEntry) right_menubar.get_last_child (); default: - var children = right_menubar.get_children (); - int index = children.index (current); - if (index == -1) { - break; - } else if (index < children.length () - 1) { // Has more than one indicator in the right menubar - sibling = children.nth_data (index + 1) as IndicatorEntry; - } else { // No more indicators on the right - var left_children = left_menubar.get_children (); - if (left_children.length () > 0) { - sibling = left_children.first ().data as IndicatorEntry; - } - } - - break; + return (IndicatorEntry) left_menubar.get_last_child (); } - - return sibling; } - private IndicatorEntry? get_previous_sibling (IndicatorEntry current) { - IndicatorEntry? sibling = null; + private IndicatorEntry? get_previous_indicator (IndicatorEntry current) { + Gtk.Widget? sibling = current.get_prev_sibling (); + + if (sibling != null) { + return (IndicatorEntry) sibling; + } switch (current.base_indicator.code_name) { case Indicator.APP_LAUNCHER: - var children = left_menubar.get_children (); - int index = children.index (current); - if (index == -1) { - break; - } else if (index != 0) { // Is not the first indicator in the left menubar - sibling = children.nth_data (index - 1) as IndicatorEntry; - } else { // No more indicators on the left - var right_children = right_menubar.get_children (); - if (right_children.length () > 0) { - sibling = right_children.last ().data as IndicatorEntry; - } - } - - break; + return (IndicatorEntry) right_menubar.get_last_child (); case Indicator.DATETIME: - var children = center_menubar.get_children (); - int index = children.index (current); - if (index == -1) { - break; - } else if (index != 0) { // Is not the first indicator in the center menubar - sibling = children.nth_data (index - 1) as IndicatorEntry; - } else { // No more indicators on the center - var left_children = left_menubar.get_children (); - if (left_children.length () > 0) { - sibling = left_children.last ().data as IndicatorEntry; - } - } - - break; + return (IndicatorEntry) left_menubar.get_last_child (); default: - var children = right_menubar.get_children (); - int index = children.index (current); - if (index == -1) { - break; - } else if (index != 0) { // Is not the first indicator in the right menubar - sibling = children.nth_data (index - 1) as IndicatorEntry; - } else { // No more indicators on the right - var center_children = center_menubar.get_children (); - if (center_children.length () > 0) { - sibling = center_children.last ().data as IndicatorEntry; - } - } - - break; + return (IndicatorEntry) center_menubar.get_last_child (); } - - return sibling; } private void add_indicator (Indicator indicator) { @@ -241,37 +132,23 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { switch (indicator.code_name) { case Indicator.APP_LAUNCHER: indicator_entry.set_transition_type (Gtk.RevealerTransitionType.SLIDE_RIGHT); - left_menubar.add (indicator_entry); + left_menubar.append (indicator_entry); break; case Indicator.DATETIME: indicator_entry.set_transition_type (Gtk.RevealerTransitionType.SLIDE_DOWN); - center_menubar.add (indicator_entry); + center_menubar.append (indicator_entry); break; default: indicator_entry.set_transition_type (Gtk.RevealerTransitionType.SLIDE_LEFT); right_menubar.insert_sorted (indicator_entry); break; } - - indicator_entry.show_all (); } private void remove_indicator (Indicator indicator) { - remove_indicator_from_container (left_menubar, indicator); - remove_indicator_from_container (center_menubar, indicator); - remove_indicator_from_container (right_menubar, indicator); - } - - private void remove_indicator_from_container (Gtk.Container container, Indicator indicator) { - foreach (unowned Gtk.Widget child in container.get_children ()) { - unowned IndicatorEntry? entry = (child as IndicatorEntry); - - if (entry != null && entry.base_indicator == indicator) { - container.remove (child); - - return; - } - } + left_menubar.remove_indicator (indicator); + center_menubar.remove_indicator (indicator); + right_menubar.remove_indicator (indicator); } private void update_background (Services.BackgroundState state, uint animation_duration) { @@ -287,7 +164,7 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { """.printf (animation_duration); try { - style_provider.load_from_data (css, css.length); + style_provider.load_from_string (css); } catch (Error e) { warning ("Parsing own style configuration failed: %s", e.message); } diff --git a/src/meson.build b/src/meson.build index d9ca1250..ad4ba59b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -16,7 +16,6 @@ wingpanel_deps = [ libwingpanel_dep, granite_dep, gdk_wl_dep, - gdk_x11_dep, posix_dep, wl_client_dep, pantheon_desktop_shell_dep diff --git a/vapi/libmutter.deps b/vapi/libmutter.deps index 1c90561b..94d101b8 100644 --- a/vapi/libmutter.deps +++ b/vapi/libmutter.deps @@ -1,7 +1,5 @@ cairo gdesktopenums-3.0 -gdk-3.0 gdk-pixbuf-2.0 -gtk+-3.0 x11 xfixes-4.0