Skip to content

Commit

Permalink
Add window cursor control
Browse files Browse the repository at this point in the history
- added new `cursor` attribute, which defaults to `false` if a window is 
full-screen
- added documentation of this
- also added in missing documentation of `fullscreen` and `screen` 
window attributes
  • Loading branch information
jonathanhogg committed Feb 8, 2025
1 parent 2c46b3d commit 45d4a87
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ window rendering tree. If not specified, it defaults to `16` bits. The color
depth of the actual `!window` on-screen frame-buffer cannot be controlled and
is OS-defined.

The `!window` node also supports the following specific attributes:

`screen=` `0`...
: Specifies which screen to open the window on. This is OS and configuration
dependent, but generally screen `0` is the "main" screen and additional screens
are numbered upwards from that. Default is `0` unless the `--screen`
[command-line option](install.md#running-flitter) has been provided.

`fullscreen=` [`true` | `false`]
: Specifies whether to show the window in full-screen mode. If set to `true`,
the window will be expanded to fill the entire screen. If the window `size`
does not match the aspect ratio of the screen then black borders will be shown
at the top/bottom or left/right sides as necessary. This attribute may be
changed programmatically to switch the window in and out of full-screen mode.
Default is `false` unless the `--fullscreen` [command-line
option](install.md#running-flitter) has been provided.

`cursor=` [`true` | `false`]
: Whether the pointer cursor should be shown within the window. This attribute
may be changed programmatically to show and hide the cursor. Default is
`true` unless the window is in full-screen mode.

The default shader program used for `!window` and `!offscreen` nodes is a
single-pass shader that composites together the output textures of all child
nodes. It can be controlled with the following additional attributes:
Expand Down
5 changes: 5 additions & 0 deletions src/flitter/render/window/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ def __init__(self, screen=0, fullscreen=False, vsync=False, offscreen=False, **k
self._visible = not offscreen
self._screen = None
self._fullscreen = None
self._cursor = None
self._resizable = None
self._title = None
self._beat = None
Expand Down Expand Up @@ -476,6 +477,7 @@ def create(self, engine, node, resized, *, opengl_es=False, **kwargs):
screen = node.get('screen', 1, int, self.default_screen)
fullscreen = node.get('fullscreen', 1, bool, self.default_fullscreen) if self._visible else False
resizable = node.get('resizable', 1, bool, True) if self._visible else False
cursor = node.get('cursor', 1, bool, not fullscreen)
title = node.get('title', 1, str, "Flitter")
if self.window is None:
self.engine = engine
Expand Down Expand Up @@ -519,6 +521,9 @@ def create(self, engine, node, resized, *, opengl_es=False, **kwargs):
if self._visible and resizable != self._resizable:
glfw.set_window_attrib(self.window, glfw.RESIZABLE, glfw.TRUE if resizable else glfw.FALSE)
self._resizable = resizable
if cursor != self._cursor:
glfw.set_input_mode(self.window, glfw.CURSOR, glfw.CURSOR_NORMAL if cursor else glfw.CURSOR_HIDDEN)
self._cursor = cursor
if self._visible and (resized or screen != self._screen or fullscreen != self._fullscreen):
monitors = glfw.get_monitors()
monitor = monitors[screen] if screen < len(monitors) else monitors[0]
Expand Down

0 comments on commit 45d4a87

Please sign in to comment.