Browse Source

Hiding and showing the cursor.

David Piuva 7 months ago
parent
commit
1cefb5b99a
1 changed files with 12 additions and 5 deletions
  1. 12 5
      Source/windowManagers/CocoaWindow.mm

+ 12 - 5
Source/windowManagers/CocoaWindow.mm

@@ -9,7 +9,7 @@
 //       On MacOS, maximizing is only supposed to enter a partial fullscreen mode where you can hover at the top to access the menu and window decorations.
 //       On MacOS, maximizing is only supposed to enter a partial fullscreen mode where you can hover at the top to access the menu and window decorations.
 //   * Minimizing the window
 //   * Minimizing the window
 //     It just bounces back instantly.
 //     It just bounces back instantly.
-//   * Setting cursor position and visibility.
+//   * Setting cursor position.
 //     Not yet implemented.
 //     Not yet implemented.
 //   * Turn off the annoying system sounds that are triggered by every key press.
 //   * Turn off the annoying system sounds that are triggered by every key press.
 
 
@@ -72,14 +72,12 @@ private:
 	// Called before the application fetches events from the input queue
 	// Called before the application fetches events from the input queue
 	//   Closing the window, moving the mouse, pressing a key, et cetera
 	//   Closing the window, moving the mouse, pressing a key, et cetera
 	void prefetchEvents() override;
 	void prefetchEvents() override;
-	/*
+
 	// Called to change the cursor visibility and returning true on success
 	// Called to change the cursor visibility and returning true on success
-	void applyCursorVisibility();
 	bool setCursorVisibility(bool visible) override;
 	bool setCursorVisibility(bool visible) override;
 
 
 	// Place the cursor within the window
 	// Place the cursor within the window
-	void setCursorPosition(int x, int y) override;
-	*/
+	//void setCursorPosition(int x, int y) override;
 private:
 private:
 	// Helper methods specific to calling XLib
 	// Helper methods specific to calling XLib
 	void updateTitle();
 	void updateTitle();
@@ -148,6 +146,15 @@ void CocoaWindow::saveToClipboard(const dsr::ReadableString &text, double timeou
 	[clipboard setString:savedText forType:NSPasteboardTypeString];
 	[clipboard setString:savedText forType:NSPasteboardTypeString];
 }
 }
 
 
+bool CocoaWindow::setCursorVisibility(bool visible) {
+	if (visible) {
+		[NSCursor unhide];
+	} else {
+		[NSCursor hide];
+	}
+	return true;
+}
+
 void CocoaWindow::setDecorations(bool decorated) {
 void CocoaWindow::setDecorations(bool decorated) {
 	// NSWindowStyleMaskFullScreen has to be preserved, because it may only be changed by full screen transitions.
 	// NSWindowStyleMaskFullScreen has to be preserved, because it may only be changed by full screen transitions.
 	static const SInt flags = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
 	static const SInt flags = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;