Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/screens.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import windy

when defined(windows) or defined(macosx):
# Screens API only currently supported on Windows and macOS

when defined(windows) or defined(macosx) or defined(linux) or defined(emscripten):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is emscripten?

# Screens API supported on all major platforms; Linux uses X11 fallback for now.
let screens = getScreens()
for screen in screens:
echo screen
10 changes: 5 additions & 5 deletions src/windy/platforms/linux/platform.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# when defined(wayland):
# include wayland
# else:
include x11
# include x11_2
when defined(wayland):
include wayland
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz

else:
include x11
# include x11_2
54 changes: 52 additions & 2 deletions src/windy/platforms/linux/wayland.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import ../../common, ../../internal, vmath, wayland/egl, wayland/protocol,
wayland/sharedBuffer
import ../../common, vmath, wayland/egl, wayland/protocol

type
OutputInfo = ref object
pos: IVec2
mode: IVec2
scale: int = 1

const defaultMode = ivec2(1920, 1080)

var outputs: seq[OutputInfo]

var
initialized: bool
Expand Down Expand Up @@ -40,6 +49,26 @@ proc init* =
shell.onPing:
shell.pong(serial)

of Output.iface:
let outputObj = registry.bindInterface(Output, name, iface, min(version, 3))
var info = OutputInfo()
outputs.add(info)

outputObj.onGeometry:
info.pos = pos

outputObj.onMode:
if ModeFlag.current in flags or info.mode == ivec2(0, 0):
info.mode = size

outputObj.onScale:
if factor > 0:
info.scale = factor

outputObj.onDone:
if info.scale <= 0:
info.scale = 1

sync display

if compositor == nil or shm == nil or shell == nil:
Expand All @@ -56,6 +85,27 @@ proc init* =

initialized = true

proc getScreens*(): seq[common.Screen] =
## Enumerate Wayland outputs and return them as Screen records.
init()
# Pump events so that output geometry/mode/scale are populated.
display.sync

if outputs.len == 0:
# Fallback: single 1920x1080 primary if no outputs were advertised.
return @[common.Screen(left: 0, top: 0, right: defaultMode.x, bottom: defaultMode.y, primary: true)]

for i, o in outputs:
let mode = if o.mode == ivec2(0, 0): defaultMode else: o.mode
let scale = max(o.scale, 1)
result.add common.Screen(
left: o.pos.x,
top: o.pos.y,
right: o.pos.x + mode.x div scale,
bottom: o.pos.y + mode.y div scale,
primary: i == 0 or o.pos == ivec2(0, 0)
)

when isMainModule:
init()
let srf = compositor.newSurface
Expand Down
17 changes: 17 additions & 0 deletions src/windy/platforms/linux/x11.nim
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,23 @@ proc `title=`*(window: Window, v: string) =
window.handle.setProperty(xaNetWMIconName, xaUTF8String, 8, v)
display.Xutf8SetWMProperties(window.handle, v, v, nil, 0, nil, nil, nil)

proc getScreens*(): seq[common.Screen] =
## Minimal screen enumeration for X11. Returns the default screen as primary.
init()

let s = display.screen(display.defaultScreen)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should return all of the screen

if s == nil:
return

let size = s.size
result.add common.Screen(
left: 0,
top: 0,
right: size.x,
bottom: size.y,
primary: true
)

proc contentScale*(window: Window): float32 =
const defaultScreenDpi = 96.0

Expand Down