x11: Implement various window functions (#12070)

This (mostly) allows the CSD added in
https://github.com/zed-industries/zed/pull/11525 to work in X11. It's
still a bit buggy as it detects a second window drag right after the
first one finishes, but it's probably better to change the way window
drags are detected in the title bar itself (as that causes other
issues).

The CSD can be tested by changing the return value of
`should_render_window_controls` to true.

Also fixes F11 crashing.

Release Notes:

- N/A
This commit is contained in:
apricotbucket28 2024-05-26 20:43:24 -03:00 committed by GitHub
parent c0259a448d
commit d8605c8614
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 195 additions and 35 deletions

View file

@ -38,11 +38,13 @@ use super::{
super::{open_uri_internal, SCROLL_LINES},
X11Display, X11WindowStatePtr, XcbAtoms,
};
use super::{button_from_mask, button_of_key, modifiers_from_state};
use super::{button_of_key, modifiers_from_state, pressed_button_from_mask};
use super::{XimCallbackEvent, XimHandler};
use crate::platform::linux::is_within_click_distance;
use crate::platform::linux::platform::DOUBLE_CLICK_INTERVAL;
pub(super) const XINPUT_MASTER_DEVICE: u16 = 1;
pub(crate) struct WindowRef {
window: X11WindowStatePtr,
refresh_event_token: RegistrationToken,
@ -183,7 +185,7 @@ impl X11Client {
);
let master_device_query = xcb_connection
.xinput_xi_query_device(1_u16)
.xinput_xi_query_device(XINPUT_MASTER_DEVICE)
.unwrap()
.reply()
.unwrap();
@ -591,7 +593,7 @@ impl X11Client {
Event::XinputMotion(event) => {
let window = self.get_window(event.event)?;
let state = self.0.borrow();
let pressed_button = button_from_mask(event.button_mask[0]);
let pressed_button = pressed_button_from_mask(event.button_mask[0]);
let position = point(
px(event.event_x as f32 / u16::MAX as f32 / state.scale_factor),
px(event.event_y as f32 / u16::MAX as f32 / state.scale_factor),
@ -674,7 +676,7 @@ impl X11Client {
let window = self.get_window(event.event)?;
let state = self.0.borrow();
let pressed_button = button_from_mask(event.buttons[0]);
let pressed_button = pressed_button_from_mask(event.buttons[0]);
let position = point(
px(event.event_x as f32 / u16::MAX as f32 / state.scale_factor),
px(event.event_y as f32 / u16::MAX as f32 / state.scale_factor),