Skip to content

Commit

Permalink
Optimized single / double click handling in TrayMediaBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
berrnd committed Mar 25, 2023
1 parent f92287f commit 417949a
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions UI/FrmVlcPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public FrmVlcPlayer(FrmMain parent)
private TransparentPanel VlcPlayerOverlayPanel;
private DateTime PlaybackStartTime;
private bool FirstPlaybackStart = true;
private bool OverlaySingleClick = true;

private void SetupVlc()
{
Expand All @@ -47,27 +48,42 @@ private void SetupVlc()
this.VlcPlayerOverlayPanel.ContextMenuStrip = this.ContextMenuStripVlcPlayerOverlayPanel;
this.PanelVlcPlayerContainer.Controls.Add(this.VlcPlayerOverlayPanel);
this.VlcPlayerOverlayPanel.BringToFront();
this.VlcPlayerOverlayPanel.DoubleClick += VlcPlayerOverlayPanel_DoubleClick;
this.VlcPlayerOverlayPanel.MouseClick += VlcPlayerOverlayPanel_MouseClick;
this.VlcPlayerOverlayPanel.MouseDoubleClick += VlcPlayerOverlayPanel_MouseDoubleClick; ;
}

private void VlcPlayerOverlayPanel_MouseClick(object sender, MouseEventArgs e)
private void VlcPlayerOverlayPanel_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.ButtonPlayPause.Enabled)
this.OverlaySingleClick = false;

// Double click handling
if (e.Button == MouseButtons.Left)
{
this.ButtonPlayPause.PerformClick();
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.WindowState = FormWindowState.Maximized;
}
}
}

private void VlcPlayerOverlayPanel_DoubleClick(object sender, EventArgs e)
private async void VlcPlayerOverlayPanel_MouseClick(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
this.OverlaySingleClick = true;
await Task.Delay(SystemInformation.DoubleClickTime);

if (!this.OverlaySingleClick)
{
this.WindowState = FormWindowState.Normal;
return;
}
else

// Single click handling
if (e.Button == MouseButtons.Left && this.ButtonPlayPause.Enabled)
{
this.WindowState = FormWindowState.Maximized;
this.ButtonPlayPause.PerformClick();
}
}

Expand Down

0 comments on commit 417949a

Please sign in to comment.