1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-09 05:34:05 +02:00

Fix various focus issues with video player and fix double-clicking control panel

This commit is contained in:
chylex 2017-08-12 15:12:54 +02:00
parent 92f1e9f7ec
commit 14a9edeb73
4 changed files with 56 additions and 12 deletions
Core
video/TweetDuck.Video

View File

@ -405,7 +405,6 @@ protected override void WndProc(ref Message m){
if (isBrowserReady && m.Msg == NativeMethods.WM_PARENTNOTIFY && (m.WParam.ToInt32() & 0xFFFF) == NativeMethods.WM_XBUTTONDOWN){
if (videoPlayer != null && videoPlayer.Running){
videoPlayer.Close();
HideVideoOverlay();
}
else{
browser.ExecuteScriptAsync("TDGF_onMouseClickExtra", (m.WParam.ToInt32() >> 16) & 0xFFFF);
@ -527,7 +526,11 @@ public void PlayVideo(string url){
if (videoPlayer == null){
videoPlayer = new VideoPlayer(this);
videoPlayer.ProcessExitedGracelessly += (sender, args) => HideVideoOverlay();
videoPlayer.ProcessExited += (sender, args) => {
browser.GetBrowser().GetHost().SendFocusEvent(true);
HideVideoOverlay();
};
}
videoPlayer.Launch(url);

View File

@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils;
namespace TweetDuck.Core.Other.Management{
@ -19,7 +20,7 @@ public bool Running{
}
}
public event EventHandler ProcessExitedGracelessly;
public event EventHandler ProcessExited;
private readonly Form owner;
private Process currentProcess;
@ -27,6 +28,7 @@ public bool Running{
public VideoPlayer(Form owner){
this.owner = owner;
this.owner.FormClosing += owner_FormClosing;
}
public void Launch(string url){
@ -66,6 +68,14 @@ public void Close(){
currentProcess.Dispose();
currentProcess = null;
owner.InvokeAsyncSafe(TriggerProcessExitEventUnsafe);
}
}
private void owner_FormClosing(object sender, FormClosingEventArgs e){
if (currentProcess != null){
currentProcess.Exited -= process_Exited;
}
}
@ -86,12 +96,14 @@ private void process_Exited(object sender, EventArgs e){
break;
}
if (currentProcess.ExitCode != 0){
ProcessExitedGracelessly?.Invoke(this, new EventArgs());
}
currentProcess.Dispose();
currentProcess = null;
owner.InvokeAsyncSafe(TriggerProcessExitEventUnsafe);
}
private void TriggerProcessExitEventUnsafe(){
ProcessExited?.Invoke(this, new EventArgs());
}
}
}

View File

@ -6,10 +6,13 @@
namespace TweetDuck.Video{
partial class FormPlayer : Form{
protected override bool ShowWithoutActivation => true;
private readonly IntPtr ownerHandle;
private readonly string videoUrl;
private readonly ControlWMP player;
private bool wasCursorInside;
private bool isPaused;
private bool isDragging;
@ -67,10 +70,12 @@ private void timerSync_Tick(object sender, EventArgs e){
int height = rect.Bottom-rect.Top+1;
IWMPMedia media = Player.currentMedia;
bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position));
ClientSize = new Size(Math.Min(media.imageSourceWidth, width*3/4), Math.Min(media.imageSourceHeight, height*3/4));
Location = new Point(rect.Left+(width-ClientSize.Width)/2, rect.Top+(height-ClientSize.Height+SystemInformation.CaptionHeight)/2);
tablePanel.Visible = ClientRectangle.Contains(PointToClient(Cursor.Position)) || isDragging;
tablePanel.Visible = isCursorInside || isDragging;
if (tablePanel.Visible){
labelTime.Text = $"{Player.controls.currentPositionString} / {Player.currentMedia.durationString}";
@ -93,6 +98,17 @@ private void timerSync_Tick(object sender, EventArgs e){
Player.controls.currentPosition = 0;
Player.controls.play();
}
if (isCursorInside && !wasCursorInside){
wasCursorInside = true;
}
else if (!isCursorInside && wasCursorInside){
wasCursorInside = false;
if (!Player.fullScreen){
NativeMethods.SetForegroundWindow(ownerHandle);
}
}
}
else{
Environment.Exit(Program.CODE_OWNER_GONE);
@ -143,23 +159,33 @@ private void TogglePause(){
internal class MessageFilter : IMessageFilter{
private readonly FormPlayer form;
private bool IsCursorOverVideo{
get{
Point cursor = form.PointToClient(Cursor.Position);
return cursor.Y < form.tablePanel.Location.Y;
}
}
public MessageFilter(FormPlayer form){
this.form = form;
}
bool IMessageFilter.PreFilterMessage(ref Message m){
if (m.Msg == 0x0201){ // WM_LBUTTONDOWN
Point cursor = form.PointToClient(Cursor.Position);
if (cursor.Y < form.tablePanel.Location.Y){
if (IsCursorOverVideo){
form.TogglePause();
return true;
}
}
else if (m.Msg == 0x0203 || (m.Msg == 0x0100 && m.WParam.ToInt32() == 0x20)){ // WM_LBUTTONDBLCLK, WM_KEYDOWN, VK_SPACE
form.TogglePause();
if (IsCursorOverVideo){
form.TogglePause();
form.Player.fullScreen = !form.Player.fullScreen;
return true;
}
}
else if (m.Msg == 0x020B && ((m.WParam.ToInt32() >> 16) & 0xFFFF) == 1){ // WM_XBUTTONDOWN
NativeMethods.SetForegroundWindow(form.ownerHandle);
Environment.Exit(Program.CODE_USER_REQUESTED);
}

View File

@ -20,6 +20,9 @@ static class NativeMethods{
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[StructLayout(LayoutKind.Sequential)]
public struct RECT{
public int Left;