Skip to content

Commit

Permalink
Add setting for workspace item size (#175)
Browse files Browse the repository at this point in the history
Provides 0.5x, 0.75x, 1.0x, 1.5x, and 2.0x sizes. Defaults to 1.0x.
  • Loading branch information
serebit authored Aug 14, 2022
1 parent dca0edd commit 5bc28a6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 12 deletions.
16 changes: 11 additions & 5 deletions src/applets/workspaces/WorkspaceItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ namespace Workspaces {
public signal void pls_update_windows();
private Gtk.Grid icon_grid;
private Gtk.Allocation real_alloc;
private float size_multiplier;

public WorkspaceItem(Wnck.Workspace space) {
public WorkspaceItem(Wnck.Workspace space, float multiplier) {
this.get_style_context().add_class("workspace-item");
this.workspace = space;
this.size_multiplier = multiplier;
this.set_tooltip_text(workspace.get_name());

real_alloc.width = 0;
Expand Down Expand Up @@ -261,6 +263,10 @@ namespace Workspaces {
this.queue_resize();
}

public void set_size_multiplier(float multiplier) {
size_multiplier = multiplier;
}

public override void size_allocate(Gtk.Allocation allocation) {
this.queue_resize();
base.size_allocate(real_alloc);
Expand Down Expand Up @@ -290,8 +296,8 @@ namespace Workspaces {
return;
}
float height = WorkspacesApplet.panel_size;
min = nat = (int) (height * 2.9);
real_alloc.width = (int) (height * 2.9);
min = nat = (int) (height * 2.9 * size_multiplier);
real_alloc.width = (int) (height * 2.9 * size_multiplier);
}

public override void get_preferred_height(out int min, out int nat) {
Expand All @@ -301,8 +307,8 @@ namespace Workspaces {
return;
}
float height = WorkspacesApplet.panel_size;
min = nat = (int) (height * 2);
real_alloc.height = (int) (height * 2);
min = nat = (int) (height * 2 * size_multiplier);
real_alloc.height = (int) (height * 2 * size_multiplier);
}

public Wnck.Workspace get_workspace() {
Expand Down
27 changes: 20 additions & 7 deletions src/applets/workspaces/WorkspacesApplet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ namespace Workspaces {
public class WorkspacesAppletSettings : Gtk.Grid {
[GtkChild]
private unowned Gtk.ComboBoxText? combobox_visibility;
[GtkChild]
private unowned Gtk.ComboBoxText? combobox_multiplier;

private Settings? settings;

public WorkspacesAppletSettings(Settings? settings) {
this.settings = settings;
settings.bind("addbutton-visibility", combobox_visibility, "active_id", SettingsBindFlags.DEFAULT);
settings.bind("item-size-multiplier", combobox_multiplier, "active_id", SettingsBindFlags.DEFAULT);
}
}

Expand All @@ -58,6 +61,7 @@ namespace Workspaces {
private List<int> dynamically_created_workspaces;
private Settings settings;
private AddButtonVisibility button_visibility = AddButtonVisibility.ALWAYS;
private float item_size_multiplier = 1.0f;

public string uuid { public set ; public get ; }

Expand Down Expand Up @@ -120,6 +124,7 @@ namespace Workspaces {
main_layout.pack_start(add_button_revealer, false, false, 0);

on_settings_change("addbutton-visibility");
on_settings_change("item-size-multiplier");

Gtk.drag_dest_set(
add_button,
Expand Down Expand Up @@ -209,13 +214,21 @@ namespace Workspaces {
}

private void on_settings_change(string key) {
if (key != "addbutton-visibility") {
return;
if (key == "addbutton-visibility") {
button_visibility = (AddButtonVisibility)settings.get_enum(key);
add_button_revealer.set_reveal_child(((button_visibility == AddButtonVisibility.ALWAYS) && below_max_workspace_count()));
} else if (key == "item-size-multiplier") {
item_size_multiplier = float.parse(settings.get_string(key));
foreach (Gtk.Widget widget in workspaces_layout.get_children()) {
Gtk.Revealer revealer = widget as Gtk.Revealer;
WorkspaceItem item = revealer.get_child() as WorkspaceItem;
item.set_size_multiplier(item_size_multiplier);
}
Timeout.add(100, () => {
update_workspaces.begin();
return true;
});
}

button_visibility = (AddButtonVisibility)settings.get_enum(key);

add_button_revealer.set_reveal_child(((button_visibility == AddButtonVisibility.ALWAYS) && below_max_workspace_count()));
}

private void populate_workspaces() {
Expand Down Expand Up @@ -278,7 +291,7 @@ namespace Workspaces {
}

private void workspace_added(Wnck.Workspace space) {
WorkspaceItem item = new WorkspaceItem(space);
WorkspaceItem item = new WorkspaceItem(space, item_size_multiplier);
var _workspace = wnck_screen.get_active_workspace();
if (_workspace != null && _workspace == space) {
item.get_style_context().add_class("current-workspace");
Expand Down
12 changes: 12 additions & 0 deletions src/applets/workspaces/com.solus-project.workspaces.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@
<value nick="hover" value="2" />
<value nick="always" value="4" />
</enum>
<enum id="com.solus-project.workspaces.ItemSizeMultiplier">
<value nick="0.5" value="1" />
<value nick="0.75" value="2" />
<value nick="1.0" value="3" />
<value nick="1.5" value="4" />
<value nick="2.0" value="5" />
</enum>
<schema id="com.solus-project.workspaces">
<key enum="com.solus-project.workspaces.AddButtonVisibility" name="addbutton-visibility">
<default>'always'</default>
<summary>Add Button Visibility</summary>
<description>Controls the visibility of the add workspace button</description>
</key>
<key enum="com.solus-project.workspaces.ItemSizeMultiplier" name="item-size-multiplier">
<default>'1.0'</default>
<summary>Item Size Multiplier</summary>
<description>A multiplier for the size of individual workspace items</description>
</key>
</schema>
</schemalist>
39 changes: 39 additions & 0 deletions src/applets/workspaces/settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,30 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">"Add" button visibility</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Item Size Multiplier</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="combobox_visibility">
<property name="visible">True</property>
Expand All @@ -35,5 +52,27 @@
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="combobox_multiplier">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="active">3</property>
<property name="active_id">1.0</property>
<items>
<item id="0.5" translatable="yes">0.5x</item>
<item id="0.75" translatable="yes">0.75x</item>
<item id="1.0" translatable="yes">1.0x</item>
<item id="1.5" translatable="yes">1.5x</item>
<item id="2.0" translatable="yes">2.0x</item>
</items>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</template>
</interface>

0 comments on commit 5bc28a6

Please sign in to comment.