Skip to content

Commit

Permalink
Add x11 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mandroll committed May 16, 2024
1 parent 0a621f2 commit cbb0061
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/native/linux_x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,27 @@ impl X11Display {
(self.libx11.XFlush)(self.display);
}

unsafe fn set_window_position(&mut self, window: Window, new_x: u32, new_y: u32) {
(self.libx11.XMoveWindow)(self.display, window, new_x, new_y);

Check failure on line 247 in src/native/linux_x11.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, armv7-unknown-linux-gnueabihf)

no field `XMoveWindow` on type `libx11::LibX11`

Check failure on line 247 in src/native/linux_x11.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

no field `XMoveWindow` on type `libx11::LibX11`

Check failure on line 247 in src/native/linux_x11.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu)

no field `XMoveWindow` on type `libx11::LibX11`
(self.libx11.XFlush)(self.display);
}

unsafe fn get_window_position(&mut self, window: Window) -> (u32, u32) {
let mut x = 0;
let mut y = 0;
(self.libx11.XTranslateCoordinates)(

Check failure on line 254 in src/native/linux_x11.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, armv7-unknown-linux-gnueabihf)

no field `XTranslateCoordinates` on type `libx11::LibX11`

Check failure on line 254 in src/native/linux_x11.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

no field `XTranslateCoordinates` on type `libx11::LibX11`

Check failure on line 254 in src/native/linux_x11.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu)

no field `XTranslateCoordinates` on type `libx11::LibX11`
self.display,
window,
self.root,
0,
0,
&mut x,
&mut y,
std::ptr::null_mut(),
);
(x, y)
}

fn show_mouse(&mut self, shown: bool) {
unsafe {
if shown {
Expand Down Expand Up @@ -324,6 +345,9 @@ impl X11Display {
new_width,
new_height,
} => self.set_window_size(self.window, new_width as _, new_height as _),
SetWindowPosition { new_x, new_y } => {
self.set_window_position(self.window, new_x as _, new_y as _)
}
SetFullscreen(fullscreen) => self.set_fullscreen(self.window, fullscreen),
ShowKeyboard(show) => {
eprintln!("Not implemented for X11")
Expand Down Expand Up @@ -366,6 +390,7 @@ where

(display.libx11.XFlush)(display.display);

// Get width and height
let (w, h) = display
.libx11
.query_window_size(display.display, display.window);
Expand Down Expand Up @@ -400,6 +425,13 @@ where
display.process_event(&mut xevent, &mut *event_handler);
}

// update screen_position if window was moved
let (x, y) = display.get_window_position(display.window);
let mut d = crate::native_display().try_lock().unwrap();
if d.screen_position.0 != x || d.screen_position.1 != y {
d.screen_position = (x, y);
}

event_handler.update();
event_handler.draw();

Expand Down

0 comments on commit cbb0061

Please sign in to comment.