Skip to content

Commit

Permalink
Merge branch 'master' into jeremypw/drag-gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Feb 22, 2024
2 parents 7b676b0 + 7794d9b commit 4240651
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 90 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: CI

on:
push:
branches: [master]
pull_request:
types:
- opened
Expand Down
5 changes: 0 additions & 5 deletions data/Display.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
-gtk-icon-palette: warning white;
}

/* Don't use alpha for the on-screen identifier */
window.colored {
background-color: alpha (@BG_COLOR, 0.8);
}

widget.colored {
border: 1px solid mix(@BG_COLOR_ALPHA, @TEXT_COLOR, 0.3);
}
Expand Down
1 change: 0 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ src/Objects/Monitor.vala
src/Views/NightLightView.vala
src/Views/DisplaysView.vala
src/Views/FiltersView.vala
src/Widgets/DisplayWindow.vala
src/Widgets/DisplayWidget.vala
src/Widgets/DisplaysOverlay.vala
19 changes: 19 additions & 0 deletions src/Interfaces/GalaDBus.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-License-Identifier: LGPL-2.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/

[DBus (name = "org.pantheon.gala.daemon")]
public interface GalaDBus : Object {
public abstract void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError;
public abstract void hide_monitor_labels () throws GLib.DBusError, GLib.IOError;
}

public struct MonitorLabelInfo {
public int monitor;
public string label;
public string background_color;
public string text_color;
public int x;
public int y;
}
20 changes: 11 additions & 9 deletions src/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright 2014–2021 elementary, Inc.
* Copyright 2014–2024 elementary, Inc.
* 2014–2018 Corentin Noël <corentin@elementary.io>
*
* This software is free software; you can redistribute it and/or
Expand Down Expand Up @@ -38,6 +38,10 @@ public class Display.DisplayWidget : Gtk.EventBox {
public double window_ratio { get; private set; default = 1.0; }
public DisplayWindow display_window { get; private set; }
public bool connected { get; set; }

public string bg_color { get; construct; }
public string text_color { get; construct; }

public Gtk.Button primary_image { get; private set; }
public Gtk.MenuButton toggle_settings { get; private set; }

Expand Down Expand Up @@ -74,15 +78,15 @@ public class Display.DisplayWidget : Gtk.EventBox {
TOTAL
}

public DisplayWidget (Display.VirtualMonitor virtual_monitor) {
Object (virtual_monitor: virtual_monitor);
public DisplayWidget (Display.VirtualMonitor virtual_monitor, string bg_color, string text_color) {
Object (
virtual_monitor: virtual_monitor,
bg_color: bg_color,
text_color: text_color
);
}

construct {
display_window = new DisplayWindow (virtual_monitor) {
attached_to = this
};

virtual_monitor.get_current_mode_size (out real_width, out real_height);

primary_image = new Gtk.Button.from_icon_name ("non-starred-symbolic") {
Expand Down Expand Up @@ -276,8 +280,6 @@ public class Display.DisplayWidget : Gtk.EventBox {
set_primary (virtual_monitor.primary);
add (grid);

destroy.connect (() => display_window.destroy ());

use_switch.bind_property ("active", resolution_combobox, "sensitive");
use_switch.bind_property ("active", rotation_combobox, "sensitive");
use_switch.bind_property ("active", refresh_combobox, "sensitive");
Expand Down
57 changes: 0 additions & 57 deletions src/Widgets/DisplayWindow.vala

This file was deleted.

57 changes: 42 additions & 15 deletions src/Widgets/DisplaysOverlay.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
private int default_y_margin = 0;

private unowned Display.MonitorManager monitor_manager;
private static GalaDBus gala_dbus = null;
public int active_displays { get; set; default = 0; }

private List<DisplayWidget> display_widgets;
Expand Down Expand Up @@ -100,6 +101,20 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
static construct {
display_provider = new Gtk.CssProvider ();
display_provider.load_from_resource ("io/elementary/switchboard/display/Display.css");

GLib.Bus.get_proxy.begin<GalaDBus> (
GLib.BusType.SESSION,
"org.pantheon.gala.daemon",
"/org/pantheon/gala/daemon",
GLib.DBusProxyFlags.NONE,
null,
(obj, res) => {
try {
gala_dbus = GLib.Bus.get_proxy.end (res);
} catch (GLib.Error e) {
critical (e.message);
}
});
}

private double prev_dx = 0;
Expand Down Expand Up @@ -188,22 +203,39 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
scanning = false;
}

public void show_windows () {
public void show_windows () requires (gala_dbus != null) {
if (monitor_manager.is_mirrored) {
return;
}

MonitorLabelInfo[] label_infos = {};

foreach (unowned var widget in display_widgets) {
if (widget.virtual_monitor.is_active) {
widget.display_window.show_all ();
label_infos += MonitorLabelInfo () {
monitor = label_infos.length,
label = widget.virtual_monitor.get_display_name (),
background_color = widget.bg_color,
text_color = widget.text_color,
x = widget.virtual_monitor.current_x,
y = widget.virtual_monitor.current_y
};
}
}

try {
gala_dbus.show_monitor_labels (label_infos);
} catch (Error e) {
warning ("Couldn't show monitor labels: %s", e.message);
}
}

public void hide_windows () {
foreach (unowned var widget in display_widgets) {
widget.display_window.hide ();
};
public void hide_windows () requires (gala_dbus != null) {
try {
gala_dbus.hide_monitor_labels ();
} catch (Error e) {
warning ("Couldn't hide monitor labels: %s", e.message);
}
}

private void change_active_displays_sensitivity () {
Expand Down Expand Up @@ -285,16 +317,16 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
}

private void add_output (Display.VirtualMonitor virtual_monitor) {
var display_widget = new DisplayWidget (virtual_monitor);
current_allocated_width = 0;
current_allocated_height = 0;

var color_number = (get_children ().length () - 2) % 7;
var display_widget = new DisplayWidget (virtual_monitor, colors[color_number], text_colors[color_number]);
add_overlay (display_widget);
display_widgets.append (display_widget);

var provider = new Gtk.CssProvider ();
try {
var color_number = (get_children ().length () - 2) % 7;

var colored_css = COLORED_STYLE_CSS.printf (colors[color_number], text_colors[color_number]);
provider.load_from_data (colored_css, colored_css.length);

Expand All @@ -303,11 +335,6 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
context.add_provider (display_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
context.add_class ("colored");

context = display_widget.display_window.get_style_context ();
context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
context.add_provider (display_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
context.add_class ("colored");

context = display_widget.primary_image.get_style_context ();
context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
context.add_provider (display_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
Expand Down Expand Up @@ -337,7 +364,7 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
});

if (!monitor_manager.is_mirrored && virtual_monitor.is_active) {
display_widget.display_window.show_all ();
show_windows ();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plug_files = files(
'Utils.vala',
'SettingsDaemon.vala',
'DisplayPlug.vala',
'Interfaces/GalaDBus.vala',
'Interfaces/NightLightManager.vala',
'Interfaces/MutterDisplayConfig.vala',
'Objects/VirtualMonitor.vala',
Expand All @@ -11,7 +12,6 @@ plug_files = files(
'Views/NightLightView.vala',
'Views/DisplaysView.vala',
'Views' / 'FiltersView.vala',
'Widgets/DisplayWindow.vala',
'Widgets/DisplayWidget.vala',
'Widgets/DisplaysOverlay.vala',
)
Expand Down

0 comments on commit 4240651

Please sign in to comment.