Skip to content

Commit 2b0ac7c

Browse files
committed
cursor-autohide support #702
1 parent 94ecf4a commit 2b0ac7c

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

docs/changelog.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
- Polish translation fixed. German, Turkish and Japanese translation updated.
55
French translation added! Thanks to the translation team!
66
- Support of relative folders from command line.
7+
- Support for the mpv option `cursor-autohide` has been added.
78
- A issue with the support of the mpv property `title-bar` has been fixed,
89
at the moment this is most useful for users of the popular uosc user script,
910
the mpv built-in OSC doesn't fully support it yet.
10-
- Set `media-controls=yes`.
11+
- Set `media-controls=yes` by default.
1112

1213

1314
# v7.1.1.1 Beta (2024-07-20)

docs/manual.md

+1
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ https://mpv.io/manual/master/#window
637637
**mpv.net has currently implemented the following window properties:**
638638

639639
- [border](https://mpv.io/manual/master/#options-border)
640+
- [cursor-autohide](https://mpv.io/manual/master/#options-cursor-autohide)
640641
- [fullscreen](https://mpv.io/manual/master/#options-fullscreen)
641642
- [keepaspect-window](https://mpv.io/manual/master/#options-keepaspect-window)
642643
- [ontop](https://mpv.io/manual/master/#options-ontop)

src/MpvNet.Windows/WinForms/MainForm.Designer.cs

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MpvNet.Windows/WinForms/MainForm.cs

+22-11
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ public partial class MainForm : Form
3838
int _lastCursorChanged;
3939
int _lastCycleFullscreen;
4040
int _taskbarButtonCreatedMessage;
41+
int _cursorAutohide = 1000;
4142

4243
bool _contextMenuIsReady;
4344
bool _wasMaximized;
4445
bool _maxSizeSet;
46+
bool _isCursorVisible = true;
4547

4648
public MainForm()
4749
{
@@ -68,9 +70,9 @@ public MainForm()
6870

6971
Player.Init(Handle, true);
7072

71-
// bool methods not working correctly
72-
Player.ObserveProperty("window-maximized", PropChangeWindowMaximized);
73-
Player.ObserveProperty("window-minimized", PropChangeWindowMinimized);
73+
Player.ObserveProperty("window-maximized", PropChangeWindowMaximized); // bool methods not working correctly
74+
Player.ObserveProperty("window-minimized", PropChangeWindowMinimized); // bool methods not working correctly
75+
Player.ObserveProperty("cursor-autohide", PropChangeCursorAutohide);
7476

7577
Player.ObservePropertyBool("border", PropChangeBorder);
7678
Player.ObservePropertyBool("fullscreen", PropChangeFullscreen);
@@ -1252,8 +1254,7 @@ void CursorTimer_Tick(object sender, EventArgs e)
12521254
_lastCursorPosition = MousePosition;
12531255
_lastCursorChanged = Environment.TickCount;
12541256
}
1255-
else if ((Environment.TickCount - _lastCursorChanged > 1500 ||
1256-
Environment.TickCount - _lastCursorChanged > 5000) &&
1257+
else if ((Environment.TickCount - _lastCursorChanged > _cursorAutohide) &&
12571258
ClientRectangle.Contains(PointToClient(MousePosition)) &&
12581259
ActiveForm == this && !ContextMenu.IsVisible && !IsMouseInOsc())
12591260

@@ -1312,6 +1313,18 @@ void PropChangeWindowMinimized()
13121313
});
13131314
}
13141315

1316+
void PropChangeCursorAutohide()
1317+
{
1318+
string strValue = Player.GetPropertyString("cursor-autohide");
1319+
1320+
if (strValue == "no")
1321+
_cursorAutohide = 0;
1322+
else if (strValue == "always")
1323+
_cursorAutohide = -1;
1324+
else if (int.TryParse(strValue, out var intValue))
1325+
_cursorAutohide = intValue;
1326+
}
1327+
13151328
void PropChangeBorder(bool enabled) {
13161329
Player.Border = enabled;
13171330

@@ -1478,20 +1491,18 @@ protected override void OnKeyDown(KeyEventArgs e)
14781491
base.OnKeyDown(e);
14791492
}
14801493

1481-
static bool _isCursorVisible = true;
1482-
1483-
static void ShowCursor()
1494+
void ShowCursor()
14841495
{
1485-
if (!_isCursorVisible)
1496+
if (!_isCursorVisible && _cursorAutohide != -1)
14861497
{
14871498
Cursor.Show();
14881499
_isCursorVisible = true;
14891500
}
14901501
}
14911502

1492-
static void HideCursor()
1503+
void HideCursor()
14931504
{
1494-
if (_isCursorVisible)
1505+
if (_isCursorVisible && _cursorAutohide != 0)
14951506
{
14961507
Cursor.Hide();
14971508
_isCursorVisible = false;

0 commit comments

Comments
 (0)