Minor improvements to the hide and show effect

This commit is contained in:
Melon 2020-10-23 11:45:59 +01:00
parent 080b1e8b2c
commit ee26a51b34
3 changed files with 48 additions and 47 deletions

View File

@ -250,7 +250,7 @@ public partial class MainWindow : Window
{ {
if (old != current) if (old != current)
{ {
string msg = (current ? "Connected to" : "Disconnected from")+" the VPN"; string msg = (current ? "Connected to" : "Disconnected from") + " the VPN";
string icon = "/usr/lib/melon-vpn/MiniMelonVPN" + (current ? "Online" : "Icon") + ".png"; string icon = "/usr/lib/melon-vpn/MiniMelonVPN" + (current ? "Online" : "Icon") + ".png";
Notification pop = new Notification("Melon VPN", msg, icon); Notification pop = new Notification("Melon VPN", msg, icon);
pop.Show(); pop.Show();
@ -301,25 +301,13 @@ public partial class MainWindow : Window
{ {
IsHidden = false; IsHidden = false;
Visible = true; // Present triggers `Visible = true;`
// it is then called again once the window is visible
// so it triggers `Deiconify();`
Present();
SkipPagerHint = false; SkipPagerHint = false;
SkipTaskbarHint = false; SkipTaskbarHint = false;
// Just wait before triggering these to get
// the right effect
Thread thread = new Thread(() =>
{
Thread.Sleep(100);
// Deiconify and Present seem to do the same
// thing but sometimes Deiconify doesn't work
Deiconify();
Present();
})
{
IsBackground = true
};
thread.Start();
UpdateTrayMenu(); UpdateTrayMenu();
} }
@ -382,8 +370,19 @@ public partial class MainWindow : Window
} }
} }
void OnRefreshClicked(object sender, EventArgs e) void OnRefreshClicked(object sender, EventArgs e) => Refresh();
protected void OnVisibilityNotifyEvent(object o, VisibilityNotifyEventArgs args)
{ {
Refresh(); // Calling present again forces the window to `Deiconify();`
Thread thread = new Thread(() =>
{
Thread.Sleep(100);
Present();
})
{
IsBackground = true
};
thread.Start();
} }
} }

View File

@ -25,5 +25,6 @@ public partial class MainWindow
this.DefaultHeight = 86; this.DefaultHeight = 86;
this.Show(); this.Show();
this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent); this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent);
this.VisibilityNotifyEvent += new global::Gtk.VisibilityNotifyEventHandler(this.OnVisibilityNotifyEvent);
} }
} }

View File

@ -13,6 +13,7 @@
<property name="Title" translatable="yes">MainWindow</property> <property name="Title" translatable="yes">MainWindow</property>
<property name="WindowPosition">CenterOnParent</property> <property name="WindowPosition">CenterOnParent</property>
<signal name="DeleteEvent" handler="OnDeleteEvent" /> <signal name="DeleteEvent" handler="OnDeleteEvent" />
<signal name="VisibilityNotifyEvent" handler="OnVisibilityNotifyEvent" />
<child> <child>
<widget class="Gtk.Fixed" id="fixed1"> <widget class="Gtk.Fixed" id="fixed1">
<property name="MemberName" /> <property name="MemberName" />