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

Fix deprecations and cleanup #557

Merged
merged 2 commits into from
Aug 11, 2024
Merged
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
6 changes: 2 additions & 4 deletions lib/IndicatorManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ public class Wingpanel.IndicatorManager : GLib.Object {
error ("Wingpanel is not supported by this system!");
}

if (!path.has_suffix (GLib.Module.SUFFIX)) {
return;
} else if (indicators.has_key (path)) {
if (indicators.has_key (path)) {
return;
} else if (check_forbidden_indicators (path)) {
debug ("Indicator %s will not be loaded since it is explicitly forbidden", path);
Expand All @@ -161,7 +159,7 @@ public class Wingpanel.IndicatorManager : GLib.Object {
return;
}

Module module = Module.open (path, ModuleFlags.BIND_LAZY);
Module module = Module.open (path, ModuleFlags.LAZY);

if (module == null) {
critical (Module.error ());
Expand Down
23 changes: 7 additions & 16 deletions src/PanelWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class Wingpanel.PanelWindow : Gtk.Window {
private Gtk.EventControllerKey key_controller; // For keeping in memory
private Gtk.GestureMultiPress gesture_controller; // For keeping in memory
private Gtk.Revealer revealer;
private int monitor_number;
private int monitor_width;
private int monitor_height;
private int panel_height;
Expand All @@ -44,8 +43,6 @@ public class Wingpanel.PanelWindow : Gtk.Window {
vexpand: false
);

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);
Expand Down Expand Up @@ -98,7 +95,7 @@ public class Wingpanel.PanelWindow : Gtk.Window {

private void on_realize () {
update_panel_dimensions ();
Services.BackgroundManager.initialize (this.monitor_number, panel_height);
Services.BackgroundManager.initialize (panel_height);

if (Utils.is_wayland ()) {
// We have to wrap in Idle otherwise the Meta.Window of the WaylandSurface in Gala is still null
Expand All @@ -111,18 +108,12 @@ public class Wingpanel.PanelWindow : Gtk.Window {
private void update_panel_dimensions () {
panel_height = panel.get_allocated_height ();

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.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 ();
}
// We just use our monitor because Gala makes sure we are always on the primary one
var monitor_dimensions = get_display ().get_monitor_at_window (get_window ()).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 ();

monitor_width = monitor_dimensions.width;
monitor_height = monitor_dimensions.height;
Expand Down
8 changes: 3 additions & 5 deletions src/Services/BackgroundManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Wingpanel.Services {
public interface InterfaceBus : Object {
public signal void state_changed (BackgroundState state, uint animation_duration);

public abstract void initialize (int monitor, int panel_height) throws GLib.Error;
public abstract void initialize (int panel_height) throws GLib.Error;
public abstract void remember_focused_window () throws GLib.Error;
public abstract void restore_focused_window () throws GLib.Error;
public abstract bool begin_grab_focused_window (int x, int y, int button, uint time, uint state) throws GLib.Error;
Expand All @@ -53,14 +53,12 @@ namespace Wingpanel.Services {
}
}

private int monitor;
private int panel_height;

public signal void background_state_changed (BackgroundState state, uint animation_duration);

public static void initialize (int monitor, int panel_height) {
public static void initialize (int panel_height) {
var manager = BackgroundManager.get_default ();
manager.monitor = monitor;
manager.panel_height = panel_height;
}

Expand Down Expand Up @@ -121,7 +119,7 @@ namespace Wingpanel.Services {
private bool connect_dbus () {
try {
bus = Bus.get_proxy_sync (BusType.SESSION, DBUS_NAME, DBUS_PATH);
bus.initialize (monitor, panel_height);
bus.initialize (panel_height);
} catch (Error e) {
warning ("Connecting to \"%s\" failed: %s", DBUS_NAME, e.message);
return false;
Expand Down
9 changes: 3 additions & 6 deletions wingpanel-interface/BackgroundManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class WingpanelInterface.BackgroundManager : Object {

public signal void state_changed (BackgroundState state, uint animation_duration);

public int monitor { private get; construct; }
public int panel_height { private get; construct; }

private ulong wallpaper_hook_id;
Expand All @@ -47,8 +46,8 @@ public class WingpanelInterface.BackgroundManager : Object {

private Utils.ColorInformation? bk_color_info = null;

public BackgroundManager (int monitor, int panel_height) {
Object (monitor : monitor, panel_height: panel_height);
public BackgroundManager (int panel_height) {
Object (panel_height: panel_height);

connect_signals ();
update_bk_color_info.begin ((obj, res) => {
Expand Down Expand Up @@ -140,9 +139,7 @@ public class WingpanelInterface.BackgroundManager : Object {
public async void update_bk_color_info () {
SourceFunc callback = update_bk_color_info.callback;

var monitor_geometry = Main.display.get_monitor_geometry (monitor);

Utils.get_background_color_information.begin (Main.wm, monitor, 0, 0, monitor_geometry.width, panel_height, (obj, res) => {
Utils.get_background_color_information.begin (Main.wm, panel_height, (obj, res) => {
try {
bk_color_info = Utils.get_background_color_information.end (res);
} catch (Error e) {
Expand Down
4 changes: 2 additions & 2 deletions wingpanel-interface/DBusServer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class WingpanelInterface.DBusServer : Object {

public signal void state_changed (BackgroundState state, uint animation_duration);

public void initialize (int monitor, int panel_height) throws GLib.Error {
background_manager = new BackgroundManager (monitor, panel_height);
public void initialize (int panel_height) throws GLib.Error {
background_manager = new BackgroundManager (panel_height);
background_manager.state_changed.connect ((state, animation_duration) => {
state_changed (state, animation_duration);
});
Expand Down
27 changes: 11 additions & 16 deletions wingpanel-interface/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ namespace WingpanelInterface.Utils {
double mean_acutance;
}

public async ColorInformation get_background_color_information (Gala.WindowManager wm, int monitor,
int reference_x, int reference_y, int reference_width, int reference_height) throws DBusError {
var bg_manager = (Gala.BackgroundManagerInterface) wm.background_group.get_child_at_index (monitor);
public async ColorInformation get_background_color_information (Gala.WindowManager wm, int panel_height) throws DBusError {
var primary = Main.display.get_primary_monitor ();
var geometry = Main.display.get_monitor_geometry (primary);

var bg_manager = (Gala.BackgroundManagerInterface) wm.background_group.get_child_at_index (primary);

if (bg_manager == null) {
throw new DBusError.INVALID_ARGS ("Invalid monitor requested: %i".printf (monitor));
throw new DBusError.INVALID_ARGS ("Couldn't get BackgroundManagerInterface on monitor %i".printf (primary));
}

var effect = new DummyOffscreenEffect ();
Expand All @@ -66,25 +68,18 @@ namespace WingpanelInterface.Utils {
// black border. The commit specifies that up to 1.75px around each side
// could now be padding, so cut off 2px from left and top if necessary
// (https://gitlab.gnome.org/GNOME/mutter/commit/8655bc5d8de6a969e0ca83eff8e450f62d28fbee)
int x_start = reference_x;
if (x_start < 2) {
x_start = 2;
}

int y_start = reference_y;
if (y_start < 2) {
y_start = 2;
}
int x_start = 2;
int y_start = 2;

// For the same reason as above, we need to not use the bottom and right
// 2px of the texture. However, if the caller has specified an area of
// interest that already misses these parts, use that instead, otherwise
// chop 2px
int width = int.min (bg_actor_width - 2 - reference_x, reference_width);
int height = int.min (bg_actor_height - 2 - reference_y, reference_height);
int width = int.min (bg_actor_width - 2, geometry.width);
int height = int.min (bg_actor_height - 2, panel_height);

if (x_start > bg_actor_width || y_start > bg_actor_height || width <= 0 || height <= 0) {
throw new DBusError.INVALID_ARGS ("Invalid rectangle specified: %i, %i, %i, %i".printf (x_start, y_start, width, height));
throw new DBusError.INVALID_ARGS ("Got invalid rectangle: %i, %i, %i, %i".printf (x_start, y_start, width, height));
}

double mean_acutance = 0, variance = 0, mean = 0, r_total = 0, g_total = 0, b_total = 0;
Expand Down
Loading