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

Initial multipanel implementation #97

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion src/lib/manager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ namespace Budgie {

public abstract uint slots_available();
public abstract uint slots_used();
public abstract void set_placement(string uuid, Budgie.PanelPosition position);
public abstract void set_placement(string uuid, Budgie.PanelPosition position, int monitor);
public abstract void set_transparency(string uuid, Budgie.PanelTransparency transparency);
public abstract void set_autohide(string uuid, Budgie.AutohidePolicy policy);
public abstract void set_dock_mode(string uuid, bool dock_mode);
public abstract void set_size(string uuid, int size);
public abstract void set_display_disconnect(string uuid, bool move_on_disconnect);
public abstract void set_spacing(string uuid, int spacing);

public abstract void create_new_panel();
Expand Down
36 changes: 20 additions & 16 deletions src/lib/toplevel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace Budgie {
* Our required size (height or width dependening on orientation
*/
public int intended_size { public set ; public get; }
public int monitor { public set ; public get; }
public bool is_disabled { public set ; public get; }

/**
* Our configured applet spacing
Expand All @@ -45,6 +47,8 @@ namespace Budgie {
public bool theme_regions { public set; public get; }
public bool dock_mode { public set; public get; default = false; }
public bool intersected { public set; public get; default = false; }
public bool move_on_disconnect { public set; public get; default = true; }


/**
* Unique identifier for this panel
Expand Down Expand Up @@ -72,40 +76,40 @@ namespace Budgie {
public abstract void remove_applet(Budgie.AppletInfo? info);
}

public static void set_struts(Gtk.Window? window, PanelPosition position, long panel_size) {
public static void set_struts(Gtk.Window? window, PanelPosition position, int monitor, long panel_size) {
Gdk.Atom atom;
long struts[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var screen = window.screen;
Gdk.Monitor mon = screen.get_display().get_primary_monitor();
Gdk.Rectangle primary_monitor_rect = mon.get_geometry();
Gdk.Monitor mon = screen.get_display().get_monitor(monitor);
Gdk.Rectangle monitor_rect = mon.get_geometry();
int scale = window.get_scale_factor();

if (!window.get_realized()) {
if (!window.get_realized() || mon == null) {
return;
}

// Struts dependent on position
switch (position) {
case PanelPosition.TOP:
struts[Struts.TOP] = (panel_size + primary_monitor_rect.y) * scale;
struts[Struts.TOP_START] = primary_monitor_rect.x * scale;
struts[Struts.TOP_END] = (primary_monitor_rect.x + primary_monitor_rect.width) * scale - 1;
struts[Struts.TOP] = (panel_size + monitor_rect.y) * scale;
struts[Struts.TOP_START] = monitor_rect.x * scale;
struts[Struts.TOP_END] = (monitor_rect.x + monitor_rect.width) * scale - 1;
break;
case PanelPosition.LEFT:
struts[Struts.LEFT] = (primary_monitor_rect.x + panel_size) * scale;
struts[Struts.LEFT_START] = primary_monitor_rect.y * scale;
struts[Struts.LEFT_END] = (primary_monitor_rect.y + primary_monitor_rect.height) * scale - 1;
struts[Struts.LEFT] = (monitor_rect.x + panel_size) * scale;
struts[Struts.LEFT_START] = monitor_rect.y * scale;
struts[Struts.LEFT_END] = (monitor_rect.y + monitor_rect.height) * scale - 1;
break;
case PanelPosition.RIGHT:
struts[Struts.RIGHT] = (panel_size + screen.get_width() - primary_monitor_rect.x - primary_monitor_rect.width) * scale;
struts[Struts.RIGHT_START] = primary_monitor_rect.y * scale;
struts[Struts.RIGHT_END] = (primary_monitor_rect.y + primary_monitor_rect.height) * scale - 1;
struts[Struts.RIGHT] = (panel_size + screen.get_width() - monitor_rect.x - monitor_rect.width) * scale;
struts[Struts.RIGHT_START] = monitor_rect.y * scale;
struts[Struts.RIGHT_END] = (monitor_rect.y + monitor_rect.height) * scale - 1;
break;
case PanelPosition.BOTTOM:
default:
struts[Struts.BOTTOM] = (panel_size + screen.get_height() - primary_monitor_rect.y - primary_monitor_rect.height) * scale;
struts[Struts.BOTTOM_START] = primary_monitor_rect.x * scale;
struts[Struts.BOTTOM_END] = (primary_monitor_rect.x + primary_monitor_rect.width) * scale - 1;
struts[Struts.BOTTOM] = (panel_size + screen.get_height() - monitor_rect.y - monitor_rect.height) * scale;
struts[Struts.BOTTOM_START] = monitor_rect.x * scale;
struts[Struts.BOTTOM_END] = (monitor_rect.x + monitor_rect.width) * scale - 1;
break;
}

Expand Down
12 changes: 12 additions & 0 deletions src/panel/com.solus-project.budgie-panel.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
<description>Height of panel if horizontal, or the width if it is vertical</description>
</key>

<key type="i" name="monitor">
<default>0</default>
<summary>Panel monitor</summary>
<description>Monitor the panel will stay on</description>
</key>

<key type="b" name="disconnect">
<default>true</default>
<summary>Move panel to primary</summary>
<description>When the display is disconnected, the associated panel is moved to the primary display</description>
</key>

<key type="i" name="spacing">
<default>2</default>
<summary>Applet spacing</summary>
Expand Down
100 changes: 75 additions & 25 deletions src/panel/manager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ namespace Budgie {
/** Panel position */
public const string PANEL_KEY_POSITION = "location";

/** Panel whether to move to primary on monitor disconnect */
public const string PANEL_KEY_DISCONNECT = "disconnect";

/** Monitor than the panel is associated with */
public const string PANEL_KEY_MONITOR = "monitor";

/** Panel transparency */
public const string PANEL_KEY_TRANSPARENCY = "transparency";

Expand Down Expand Up @@ -374,7 +380,7 @@ namespace Budgie {
}

/*
* Decide wether or not the panel should be opaque
* Decide whether or not the panel should be opaque
* The panel should be opaque when:
* - Raven is open
* - a window fills these requirements:
Expand Down Expand Up @@ -498,17 +504,31 @@ namespace Budgie {
/* Fix all existing panels here */
Gdk.Rectangle raven_screen;

unowned Screen? monitor_screen;

iter = HashTableIter<string,Budgie.Panel?>(panels);
while (iter.next(out uuid, out panel)) {
/* Force existing panels to update to new primary display */
panel.update_geometry(primary.area, panel.position);
monitor_screen = screens.lookup(panel.monitor);

if (monitor_screen == null) {
panel.is_disabled = true;
continue;
} else {
panel.update_geometry(monitor_screen.area, panel.position, panel.monitor);
panel.is_disabled = false;
}

if (panel.position == Budgie.PanelPosition.TOP) {
top = panel;
} else if (panel.position == Budgie.PanelPosition.BOTTOM) {
bottom = panel;
}
/* Re-take the position */
primary.slots |= panel.position;

if (panel.move_on_disconnect) {
/* Re-take the position */
monitor_screen.slots |= panel.position;
}
}

raven_screen = primary.area;
Expand Down Expand Up @@ -897,6 +917,7 @@ namespace Budgie {

string path = this.create_panel_path(uuid);
PanelPosition position;
int monitor;
PanelTransparency transparency;
AutohidePolicy policy;
bool dock_mode;
Expand All @@ -916,14 +937,16 @@ namespace Budgie {
policy = (AutohidePolicy)settings.get_enum(Budgie.PANEL_KEY_AUTOHIDE);
dock_mode = settings.get_boolean(Budgie.PANEL_KEY_DOCK_MODE);
shadow_visible = settings.get_boolean(Budgie.PANEL_KEY_SHADOW);
monitor = settings.get_int(Budgie.PANEL_KEY_MONITOR);
panel.move_on_disconnect = settings.get_boolean(Budgie.PANEL_KEY_DISCONNECT);

size = settings.get_int(Budgie.PANEL_KEY_SIZE);
panel.intended_size = (int)size;
spacing = (int) settings.get_int(Budgie.PANEL_KEY_SPACING);
this.show_panel(uuid, position, transparency, policy, dock_mode, shadow_visible, spacing);
this.show_panel(uuid, position, monitor, transparency, policy, dock_mode, shadow_visible, spacing);
}

void show_panel(string uuid, PanelPosition position, PanelTransparency transparency, AutohidePolicy policy,
void show_panel(string uuid, PanelPosition position, int monitor, PanelTransparency transparency, AutohidePolicy policy,
bool dock_mode, bool shadow_visible, int spacing) {

Budgie.Panel? panel = panels.lookup(uuid);
Expand All @@ -934,9 +957,15 @@ namespace Budgie {
return;
}

scr = screens.lookup(this.primary_monitor);
scr = screens.lookup(monitor);

if (scr == null) {
panel.is_disabled = true;
return;
}

scr.slots |= position;
this.set_placement(uuid, position);
this.set_placement(uuid, position, monitor);
this.set_transparency(uuid, transparency);
this.set_autohide(uuid, policy);
this.set_dock_mode(uuid, dock_mode);
Expand Down Expand Up @@ -977,7 +1006,7 @@ namespace Budgie {
/**
* Enforce panel placement
*/
public override void set_placement(string uuid, PanelPosition position) {
public override void set_placement(string uuid, PanelPosition position, int monitor) {
Budgie.Panel? panel = panels.lookup(uuid);
string? key = null;
Budgie.Panel? val = null;
Expand All @@ -987,19 +1016,21 @@ namespace Budgie {
warning("Trying to move non-existent panel: %s", uuid);
return;
}
Screen? area = screens.lookup(primary_monitor);
Screen? area = screens.lookup(monitor);
Screen? old_area = screens.lookup(panel.monitor);

PanelPosition old = panel.position;
PanelPosition old_position = panel.position;
int old_monitor = panel.monitor;

if (old == position) {
warning("Attempting to move panel to the same position it's already in: %s %s %s", uuid, old.to_string(), position.to_string());
if (old_position == position && old_monitor == monitor) {
warning("Attempting to move panel to the same position it's already in: %s %s %s", uuid, old_position.to_string(), position.to_string());
return;
}

/* Attempt to find a conflicting position */
var iter = HashTableIter<string,Budgie.Panel?>(panels);
while (iter.next(out key, out val)) {
if (val.position == position) {
if (val.position == position && val.monitor == monitor) {
conflict = val;
break;
}
Expand All @@ -1008,15 +1039,15 @@ namespace Budgie {
panel.hide();
if (conflict != null) {
conflict.hide();
conflict.update_geometry(area.area, old);
conflict.update_geometry(old_area.area, old_position, old_monitor);
conflict.show();
panel.hide();
panel.update_geometry(area.area, position);
panel.update_geometry(area.area, position, monitor);
panel.show();
} else {
area.slots ^= old;
old_area.slots ^= old_position;
area.slots |= position;
panel.update_geometry(area.area, position);
panel.update_geometry(area.area, position, monitor);
}

/* This does mean re-configuration a couple of times that could
Expand All @@ -1026,6 +1057,17 @@ namespace Budgie {
panel.show();
}

public override void set_display_disconnect(string uuid, bool move_on_disconnect) {
Budgie.Panel? panel = panels.lookup(uuid);

if (panel == null) {
warning("Trying to set disconnect on non-existent panel: %s", uuid);
return;
}

panel.move_on_disconnect = move_on_disconnect;
}

/**
* Set panel transparency
*/
Expand Down Expand Up @@ -1123,25 +1165,30 @@ namespace Budgie {
Budgie.Panel? val2 = null;

while (iter2.next(out key2, out val2)) {
if (val2.is_disabled)
continue;

Screen? area_proper = screens.lookup(val2.monitor);

switch (val2.position) {
case Budgie.PanelPosition.LEFT:
case Budgie.PanelPosition.RIGHT:
Gdk.Rectangle geom = Gdk.Rectangle();
geom.x = area.area.x;
geom.y = area.area.y;
geom.width = area.area.width;
geom.height = area.area.height;
geom.x = area_proper.area.x;
geom.y = area_proper.area.y;
geom.width = area_proper.area.width;
geom.height = area_proper.area.height;
if (this.is_panel_huggable(top)) {
geom.y += top.intended_size;
geom.height -= top.intended_size;
}
if (this.is_panel_huggable(bottom)) {
geom.height -= bottom.intended_size;
}
val2.update_geometry(geom, val2.position, val2.intended_size);
val2.update_geometry(geom, val2.position, val2.monitor, val2.intended_size);
break;
default:
val2.update_geometry(area.area, val2.position, val2.intended_size);
val2.update_geometry(area.area, val2.position, val2.monitor, val2.intended_size);
break;
}
}
Expand Down Expand Up @@ -1289,6 +1336,7 @@ namespace Budgie {

void create_panel(string? name = null, KeyFile? new_defaults = null) {
PanelPosition position = PanelPosition.NONE;
int monitor = 0;
PanelTransparency transparency = PanelTransparency.NONE;
Budgie.AutohidePolicy policy = Budgie.AutohidePolicy.NONE;
bool dock_mode = false;
Expand Down Expand Up @@ -1373,7 +1421,9 @@ namespace Budgie {
load_panel(uuid, false);

set_panels();
show_panel(uuid, position, transparency, policy, dock_mode, shadow_visible, spacing);

// TODO: Pick a safe default monitor docation
show_panel(uuid, position, monitor, transparency, policy, dock_mode, shadow_visible, spacing);

if (new_defaults == null || name == null) {
this.panel_added(uuid, panels.lookup(uuid));
Expand Down
10 changes: 8 additions & 2 deletions src/panel/panel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace Budgie {
/**
* Force update the geometry
*/
public void update_geometry(Gdk.Rectangle screen, PanelPosition position, int size = 0) {
public void update_geometry(Gdk.Rectangle screen, PanelPosition position, int monitor, int size = 0) {
this.orig_scr = screen;
string old_class = Budgie.position_class_name(this.position);

Expand All @@ -162,6 +162,9 @@ namespace Budgie {
this.update_positions();
}

this.monitor = monitor;
this.settings.set_int(Budgie.PANEL_KEY_MONITOR, this.monitor);

this.shadow.position = position;
this.layout.queue_resize();
queue_resize();
Expand Down Expand Up @@ -334,6 +337,9 @@ namespace Budgie {
shadow.show_all();
main_layout.pack_start(shadow, false, false, 0);

move_on_disconnect = this.settings.get_boolean(Budgie.PANEL_KEY_DISCONNECT);
this.settings.bind(Budgie.PANEL_KEY_DISCONNECT, this, "move-on-disconnect", SettingsBindFlags.DEFAULT);

this.settings.bind(Budgie.PANEL_KEY_SHADOW, shadow, "active", SettingsBindFlags.GET);
this.settings.bind(Budgie.PANEL_KEY_DOCK_MODE, this, "dock-mode", SettingsBindFlags.DEFAULT);

Expand Down Expand Up @@ -1072,7 +1078,7 @@ namespace Budgie {
if (this.autohide != AutohidePolicy.NONE) {
Budgie.unset_struts(this);
} else {
Budgie.set_struts(this, position, intended_size);
Budgie.set_struts(this, position, this.monitor, intended_size);
}
}

Expand Down
Loading