Skip to content

Commit

Permalink
Use Adw.Spinner instead of Gtk.Spinner when libadwaita 1.6 is available
Browse files Browse the repository at this point in the history
  • Loading branch information
ztefn committed Sep 21, 2024
1 parent c40c10a commit 35c56a1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
4 changes: 1 addition & 3 deletions data/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,10 @@
<object class="GtkStackPage">
<property name="name">Connecting</property>
<property name="child">
<object class="GtkSpinner" id="spinner">
<object class="HaguichiThrobber" id="throbber">
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin-bottom">12</property>
<property name="width-request">20</property>
<property name="height-request">20</property>
</object>
</property>
</object>
Expand Down
8 changes: 8 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sources = [
'widgets/commands-editor-row.vala',
'widgets/sidebar-row.vala',
'widgets/sidebar-page.vala',
'widgets/throbber.vala',
'window.vala',
]

Expand All @@ -48,6 +49,13 @@ deps = [
dependency('libportal-gtk4', version: '>= 0.7.1'),
]

if dependency('libadwaita-1').version().version_compare('>= 1.6')
add_project_arguments(
['-D', 'ADW_1_6'],
language: 'vala'
)
endif

executable(binary_name, config, sources, resources,
dependencies: deps,
install: true,
Expand Down
44 changes: 44 additions & 0 deletions src/widgets/throbber.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of Haguichi, a graphical frontend for Hamachi.
* Copyright (C) 2007-2024 Stephen Brandt <[email protected]>
*
* Haguichi 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 3 of the License,
* or (at your option) any later version.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#if ADW_1_6
using Adw;
#else
using Gtk;
#endif

namespace Haguichi {
public class Throbber : Adw.Bin {
public Spinner spinner;

construct {
spinner = new Spinner () {
width_request = 20,
height_request = 20
};
set_child (spinner);
}

public bool spinning {
#if ADW_1_6
get; set;
#else
get {
return spinner.spinning;
}
set {
spinner.spinning = value;
}
#endif
}
}
}
4 changes: 2 additions & 2 deletions src/window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Haguichi {
public unowned Gtk.Stack connected_stack;

[GtkChild]
public unowned Gtk.Spinner spinner;
public unowned Throbber throbber;

[GtkChild]
private unowned Gtk.Button configure_button;
Expand Down Expand Up @@ -398,7 +398,7 @@ namespace Haguichi {
hide_sidebar ();
}

spinner.spinning = (mode == "Connecting");
throbber.spinning = (mode == "Connecting");

configure_button.sensitive = (mode == "Not configured");

Expand Down

0 comments on commit 35c56a1

Please sign in to comment.