some state and FORMATTING BB

main
Zynh0722 2024-01-31 22:34:50 -08:00
parent f6654ed34a
commit 456f56f5b5
3 changed files with 61 additions and 5 deletions

View File

@ -1,10 +1,9 @@
mod setup; mod setup;
mod state;
use setup::{become_wm, handle_args}; use setup::{become_wm, handle_args};
use x11rb::{ use x11rb::{connect, connection::Connection};
connect, connection::Connection,
};
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
handle_args(); handle_args();

View File

@ -1,9 +1,15 @@
use anyhow::anyhow; use anyhow::anyhow;
use x11rb::{connection::Connection, protocol::xproto::{ConnectionExt, Screen}}; use x11rb::{
connection::Connection,
protocol::xproto::{ConnectionExt, Screen},
};
pub fn become_wm<C: Connection>(conn: &C, screen: &Screen) -> anyhow::Result<()> { pub fn become_wm<C: Connection>(conn: &C, screen: &Screen) -> anyhow::Result<()> {
use x11rb::{protocol::xproto::{ChangeWindowAttributesAux, EventMask}, xcb_ffi::ReplyError}; use x11rb::{
protocol::xproto::{ChangeWindowAttributesAux, EventMask},
xcb_ffi::ReplyError,
};
let change = ChangeWindowAttributesAux::default() let change = ChangeWindowAttributesAux::default()
.event_mask(EventMask::SUBSTRUCTURE_REDIRECT | EventMask::SUBSTRUCTURE_NOTIFY); .event_mask(EventMask::SUBSTRUCTURE_REDIRECT | EventMask::SUBSTRUCTURE_NOTIFY);

51
src/state.rs Normal file
View File

@ -0,0 +1,51 @@
use x11rb::connection::Connection;
use x11rb::protocol::xproto::{Atom, ConnectionExt, CreateGCAux, Gcontext, Window};
use x11rb::xcb_ffi::ReplyOrIdError;
#[derive(Debug)]
pub struct WmState<'a, C: Connection> {
pub conn: &'a C,
pub screen_num: usize,
pub black_gc: Gcontext,
pub windows: Vec<WinState>,
pub wm_protocols: Atom,
pub wm_delete_window: Atom,
}
impl<'a, C: Connection> WmState<'a, C> {
pub fn new(conn: &'a C, screen_num: usize) -> Result<WmState<'a, C>, ReplyOrIdError> {
let screen = &conn.setup().roots[screen_num];
let black_gc = conn.generate_id()?;
let font = conn.generate_id()?;
conn.open_font(font, b"9x15")?;
let gc_aux = CreateGCAux::new()
.graphics_exposures(0)
.background(screen.white_pixel)
.foreground(screen.black_pixel)
.font(font);
conn.create_gc(black_gc, screen.root, &gc_aux)?;
conn.close_font(font)?;
let wm_protocols = conn.intern_atom(false, b"WM_PROTOCOLS")?;
let wm_delete_window = conn.intern_atom(false, b"WM_DELETE_WINDOW")?;
Ok(WmState {
conn: conn,
screen_num: screen_num,
black_gc: black_gc,
windows: Vec::default(),
wm_protocols: wm_protocols.reply()?.atom,
wm_delete_window: wm_delete_window.reply()?.atom,
})
}
}
#[derive(Debug)]
pub struct WinState {
pub window: Window,
pub frame_window: Window,
pub x: i16,
pub y: i16,
pub width: u16,
}