Skip to content

Commit 2310f18

Browse files
authored
fix(Main): switcher state and breakpoints between is_mobile (#735)
1 parent 1dd9488 commit 2310f18

6 files changed

Lines changed: 36 additions & 27 deletions

File tree

src/Application.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace Tuba {
3030

3131
public Dialogs.MainWindow? main_window { get; set; }
3232
public Dialogs.NewAccount? add_account_window { get; set; }
33+
public bool is_mobile { get; set; default=false; }
3334

3435
public Locales app_locales { get; construct set; }
3536

src/Dialogs/MainWindow.vala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
1212
sidebar.set_sidebar_selected_item (pos);
1313
}
1414

15-
public bool is_mobile { get; set; default = false; }
16-
1715
Views.Base? last_view = null;
1816

1917
construct {
2018
construct_saveable (settings);
2119

2220
var gtk_settings = Gtk.Settings.get_default ();
23-
breakpoint.add_setter (this, "is-mobile", true);
24-
notify["is-mobile"].connect (update_selected_home_item);
21+
breakpoint.add_setter (app, "is-mobile", true);
22+
app.notify["is-mobile"].connect (update_selected_home_item);
2523
media_viewer.bind_property ("visible", split_view, "can-focus", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN);
2624
media_viewer.notify["visible"].connect (on_media_viewer_toggle);
2725

@@ -194,7 +192,7 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
194192

195193
public void update_selected_home_item () {
196194
if (is_home) {
197-
if (is_mobile) {
195+
if (app.is_mobile) {
198196
set_sidebar_selected_item (0);
199197
} else {
200198
var main_view = main_page.child as Views.Main;

src/Services/Accounts/Mastodon/Account.vala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,9 @@ public class Tuba.Mastodon.Account : InstanceAccount {
157157
};
158158

159159
public override void register_known_places (GLib.ListStore places) {
160-
ulong main_window_notify = 0;
161-
main_window_notify = app.notify["main-window"].connect (() => {
162-
app.main_window.bind_property ("is-mobile", PLACE_NOTIFICATIONS, "visible", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN);
163-
app.main_window.bind_property ("is-mobile", PLACE_CONVERSATIONS, "visible", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN);
164-
app.main_window.bind_property ("is-mobile", PLACE_SEARCH, "visible", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN);
165-
app.disconnect (main_window_notify);
166-
});
160+
app.bind_property ("is-mobile", PLACE_NOTIFICATIONS, "visible", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN);
161+
app.bind_property ("is-mobile", PLACE_CONVERSATIONS, "visible", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN);
162+
app.bind_property ("is-mobile", PLACE_SEARCH, "visible", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN);
167163

168164
places.append (PLACE_HOME);
169165
places.append (PLACE_NOTIFICATIONS);

src/Views/Home.vala

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,10 @@ public class Tuba.Views.Home : Views.Timeline {
3838
});
3939
#endif
4040

41-
ulong main_window_notify = 0;
42-
main_window_notify = app.notify["main-window"].connect (() => {
43-
app.disconnect (main_window_notify);
44-
45-
app.main_window.notify["is-mobile"].connect (() => {
46-
if (!app.main_window.is_mobile)
47-
compose_button_rev.reveal_child = true;
48-
});
49-
});
41+
app.notify["is-mobile"].connect (() => {
42+
if (!app.is_mobile)
43+
compose_button_rev.reveal_child = true;
44+
});
5045
}
5146

5247
void toggle_scroll_to_top_margin () {
@@ -58,7 +53,7 @@ public class Tuba.Views.Home : Views.Timeline {
5853
bool last_direction_down = false;
5954
protected override void on_scrolled_vadjustment_value_change () {
6055
base.on_scrolled_vadjustment_value_change ();
61-
if (app.main_window?.is_mobile != true) return;
56+
if (app.is_mobile != true) return;
6257

6358
double trunced = Math.trunc (scrolled.vadjustment.value);
6459
bool direction_down = trunced == last_adjustment ? last_direction_down : trunced > last_adjustment;

src/Views/Main.vala

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,32 @@ public class Tuba.Views.Main : Views.TabbedBase {
2424
// app.main_window.update_selected_home_item ();
2525
// }
2626

27+
private Gtk.Stack title_wrapper_stack;
28+
public bool title_wrapper_stack_visible {
29+
get {
30+
return title_wrapper_stack.visible_child_name == "title";
31+
}
32+
set {
33+
title_wrapper_stack.visible_child_name = (value ? "stack" : "title");
34+
}
35+
}
36+
2737
private void bind () {
28-
app.main_window.bind_property ("is-mobile", search_button, "visible", GLib.BindingFlags.SYNC_CREATE);
29-
app.main_window.bind_property ("is-mobile", switcher_bar, "visible", GLib.BindingFlags.SYNC_CREATE);
30-
app.main_window.bind_property ("is-mobile", switcher, "visible", GLib.BindingFlags.SYNC_CREATE);
38+
app.bind_property ("is-mobile", search_button, "visible", GLib.BindingFlags.SYNC_CREATE);
39+
app.bind_property ("is-mobile", switcher_bar, "visible", GLib.BindingFlags.SYNC_CREATE);
40+
app.bind_property ("is-mobile", this, "title-wrapper-stack-visible", GLib.BindingFlags.SYNC_CREATE);
3141
}
3242

3343
public override void build_header () {
3444
base.build_header ();
45+
header.title_widget = null;
46+
47+
title_wrapper_stack = new Gtk.Stack ();
48+
title_wrapper_stack.add_named (title_stack, "stack");
49+
var title_header = new Adw.WindowTitle (label, "");
50+
bind_property ("label", title_header, "title", BindingFlags.SYNC_CREATE);
51+
title_wrapper_stack.add_named (title_header, "title");
52+
header.title_widget = title_wrapper_stack;
3553

3654
search_button = new Gtk.Button () {
3755
icon_name = "tuba-loupe-large-symbolic",
@@ -44,14 +62,14 @@ public class Tuba.Views.Main : Views.TabbedBase {
4462
header.pack_start (sidebar_button);
4563
sidebar_button.icon_name = "tuba-dock-left-symbolic";
4664

65+
bind ();
4766
ulong main_window_notify = 0;
4867
main_window_notify = app.notify["main-window"].connect (() => {
4968
if (app.main_window == null) {
5069
sidebar_button.hide ();
5170
return;
5271
}
5372

54-
bind ();
5573
app.main_window.split_view.bind_property (
5674
"collapsed",
5775
sidebar_button,

src/Views/TabbedBase.vala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class Tuba.Views.TabbedBase : Views.Base {
5252
}
5353

5454
set {
55-
title_stack.visible_child_name = value ? "title" : "switcher";
55+
title_stack.visible_child_name = (value ? "title" : "switcher");
5656
}
5757
}
5858

@@ -70,6 +70,7 @@ public class Tuba.Views.TabbedBase : Views.Base {
7070
bind_property ("label", title_header, "title", BindingFlags.SYNC_CREATE);
7171
title_stack.add_named (title_header, "title");
7272

73+
title_stack_page_visible = false;
7374
var condition = new Adw.BreakpointCondition.length (
7475
Adw.BreakpointConditionLengthType.MAX_WIDTH,
7576
550, Adw.LengthUnit.SP

0 commit comments

Comments
 (0)