Skip to content

Commit

Permalink
cursor-autohide support #702
Browse files Browse the repository at this point in the history
  • Loading branch information
stax76 committed Oct 10, 2024
1 parent 94ecf4a commit 2b0ac7c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
- Polish translation fixed. German, Turkish and Japanese translation updated.
French translation added! Thanks to the translation team!
- Support of relative folders from command line.
- Support for the mpv option `cursor-autohide` has been added.
- A issue with the support of the mpv property `title-bar` has been fixed,
at the moment this is most useful for users of the popular uosc user script,
the mpv built-in OSC doesn't fully support it yet.
- Set `media-controls=yes`.
- Set `media-controls=yes` by default.


# v7.1.1.1 Beta (2024-07-20)
Expand Down
1 change: 1 addition & 0 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ https://mpv.io/manual/master/#window
**mpv.net has currently implemented the following window properties:**

- [border](https://mpv.io/manual/master/#options-border)
- [cursor-autohide](https://mpv.io/manual/master/#options-cursor-autohide)
- [fullscreen](https://mpv.io/manual/master/#options-fullscreen)
- [keepaspect-window](https://mpv.io/manual/master/#options-keepaspect-window)
- [ontop](https://mpv.io/manual/master/#options-ontop)
Expand Down
2 changes: 1 addition & 1 deletion src/MpvNet.Windows/WinForms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 22 additions & 11 deletions src/MpvNet.Windows/WinForms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public partial class MainForm : Form
int _lastCursorChanged;
int _lastCycleFullscreen;
int _taskbarButtonCreatedMessage;
int _cursorAutohide = 1000;

bool _contextMenuIsReady;
bool _wasMaximized;
bool _maxSizeSet;
bool _isCursorVisible = true;

public MainForm()
{
Expand All @@ -68,9 +70,9 @@ public MainForm()

Player.Init(Handle, true);

// bool methods not working correctly
Player.ObserveProperty("window-maximized", PropChangeWindowMaximized);
Player.ObserveProperty("window-minimized", PropChangeWindowMinimized);
Player.ObserveProperty("window-maximized", PropChangeWindowMaximized); // bool methods not working correctly
Player.ObserveProperty("window-minimized", PropChangeWindowMinimized); // bool methods not working correctly
Player.ObserveProperty("cursor-autohide", PropChangeCursorAutohide);

Player.ObservePropertyBool("border", PropChangeBorder);
Player.ObservePropertyBool("fullscreen", PropChangeFullscreen);
Expand Down Expand Up @@ -1252,8 +1254,7 @@ void CursorTimer_Tick(object sender, EventArgs e)
_lastCursorPosition = MousePosition;
_lastCursorChanged = Environment.TickCount;
}
else if ((Environment.TickCount - _lastCursorChanged > 1500 ||
Environment.TickCount - _lastCursorChanged > 5000) &&
else if ((Environment.TickCount - _lastCursorChanged > _cursorAutohide) &&
ClientRectangle.Contains(PointToClient(MousePosition)) &&
ActiveForm == this && !ContextMenu.IsVisible && !IsMouseInOsc())

Expand Down Expand Up @@ -1312,6 +1313,18 @@ void PropChangeWindowMinimized()
});
}

void PropChangeCursorAutohide()
{
string strValue = Player.GetPropertyString("cursor-autohide");

if (strValue == "no")
_cursorAutohide = 0;
else if (strValue == "always")
_cursorAutohide = -1;
else if (int.TryParse(strValue, out var intValue))
_cursorAutohide = intValue;
}

void PropChangeBorder(bool enabled) {
Player.Border = enabled;

Expand Down Expand Up @@ -1478,20 +1491,18 @@ protected override void OnKeyDown(KeyEventArgs e)
base.OnKeyDown(e);
}

static bool _isCursorVisible = true;

static void ShowCursor()
void ShowCursor()
{
if (!_isCursorVisible)
if (!_isCursorVisible && _cursorAutohide != -1)
{
Cursor.Show();
_isCursorVisible = true;
}
}

static void HideCursor()
void HideCursor()
{
if (_isCursorVisible)
if (_isCursorVisible && _cursorAutohide != 0)
{
Cursor.Hide();
_isCursorVisible = false;
Expand Down

0 comments on commit 2b0ac7c

Please sign in to comment.