1
0
Fork 0
forked from wry/wry

autocommit 2022-03-30 18:10:37 CEST

This commit is contained in:
Julian Orth 2022-03-30 18:10:37 +02:00
parent c4854c4d7d
commit a8136ed88c
17 changed files with 189 additions and 81 deletions

View file

@ -4,13 +4,14 @@ use crate::_private::ipc::{ClientMessage, InitMessage, Response, ServerMessage};
use crate::_private::{bincode_ops, logging, Config, ConfigEntry, ConfigEntryGen, VERSION};
use crate::keyboard::keymap::Keymap;
use crate::theme::Color;
use crate::{Axis, Command, Direction, InputDevice, LogLevel, ModifiedKeySym, Seat};
use crate::{Axis, Command, Direction, LogLevel, ModifiedKeySym, Seat};
use std::cell::{Cell, RefCell};
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::ops::Deref;
use std::rc::Rc;
use std::{ptr, slice};
use crate::input::{Capability, InputDevice};
pub(crate) struct Client {
configure: extern "C" fn(),
@ -317,6 +318,17 @@ impl Client {
self.send(&ClientMessage::SetSeat { device, seat })
}
pub fn has_capability(&self, device: InputDevice, cap: Capability) -> bool {
let res = self.with_response(|| self.send(&ClientMessage::HasCapability { device, cap }));
match res {
Response::HasCapability { has } => has,
_ => {
log::error!("Server did not send a response to a has_capability request");
false
}
}
}
pub fn seat_set_keymap(&self, seat: Seat, keymap: Keymap) {
self.send(&ClientMessage::SeatSetKeymap { seat, keymap })
}

View file

@ -2,8 +2,9 @@ use crate::keyboard::keymap::Keymap;
use crate::keyboard::mods::Modifiers;
use crate::keyboard::syms::KeySym;
use crate::theme::Color;
use crate::{Axis, Direction, InputDevice, LogLevel, Seat};
use crate::{Axis, Direction, LogLevel, Seat};
use bincode::{BorrowDecode, Decode, Encode};
use crate::input::{Capability, InputDevice};
#[derive(Encode, BorrowDecode, Debug)]
pub enum ServerMessage {
@ -136,6 +137,10 @@ pub enum ClientMessage<'a> {
ToggleFloating {
seat: Seat,
},
HasCapability {
device: InputDevice,
cap: Capability,
},
}
#[derive(Encode, Decode, Debug)]
@ -150,6 +155,7 @@ pub enum Response {
GetInputDevices { devices: Vec<InputDevice> },
GetTitleHeight { height: i32 },
GetBorderWidth { width: i32 },
HasCapability { has: bool },
}
#[derive(Encode, Decode, Debug)]

View file

@ -1,4 +1,4 @@
use crate::InputDevice;
use crate::input::InputDevice;
pub fn grab_input_device(kb: InputDevice, grab: bool) {
get!().grab(kb, grab);

26
jay-config/src/input.rs Normal file
View file

@ -0,0 +1,26 @@
use bincode::{Decode, Encode};
use crate::Seat;
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct InputDevice(pub u64);
impl InputDevice {
pub fn set_seat(self, seat: Seat) {
get!().set_seat(self, seat)
}
pub fn has_capability(self, cap: Capability) -> bool {
get!(false).has_capability(self, cap)
}
}
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Capability(pub u32);
pub const CAP_KEYBOARD: Capability = Capability(0);
pub const CAP_POINTER: Capability = Capability(1);
pub const CAP_TOUCH: Capability = Capability(2);
pub const CAP_TABLET_TOOL: Capability = Capability(3);
pub const CAP_TABLET_PAD: Capability = Capability(4);
pub const CAP_GESTURE: Capability = Capability(5);
pub const CAP_SWITCH: Capability = Capability(6);

View file

@ -2,6 +2,7 @@ use crate::keyboard::keymap::Keymap;
use crate::keyboard::ModifiedKeySym;
use bincode::{Decode, Encode};
use std::collections::HashMap;
use crate::input::InputDevice;
#[macro_use]
mod macros;
@ -10,6 +11,7 @@ pub mod _private;
pub mod embedded;
pub mod keyboard;
pub mod theme;
pub mod input;
#[derive(Encode, Decode, Copy, Clone, Debug)]
pub enum LogLevel {
@ -39,15 +41,6 @@ impl Seat {
}
}
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct InputDevice(pub u64);
impl InputDevice {
pub fn set_seat(self, seat: Seat) {
get!().set_seat(self, seat)
}
}
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum Axis {
Horizontal,

View file

@ -17,11 +17,14 @@ macro_rules! config {
macro_rules! get {
() => {{
get!(())
}};
($def:expr) => {{
#[allow(unused_unsafe)]
let client = unsafe {
let client = crate::_private::client::CLIENT.with(|client| client.get());
if client.is_null() {
return;
return $def;
}
&*client
};