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
2 changes: 2 additions & 0 deletions src/x11/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,12 @@ impl EventLoop {
}

XEvent::FocusIn(_) => {
self.window.is_focused.set(true);
self.handle_event(Event::Window(WindowEvent::Focused));
}

XEvent::FocusOut(_) => {
self.window.is_focused.set(false);
self.handle_event(Event::Window(WindowEvent::Unfocused));
}

Expand Down
18 changes: 13 additions & 5 deletions src/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ use raw_window_handle::{
use x11rb::connection::Connection;
use x11rb::protocol::xproto::{
AtomEnum, ChangeWindowAttributesAux, ConfigureWindowAux, ConnectionExt, CreateGCAux,
CreateWindowAux, EventMask, PropMode, Visualid, Window as XWindow, WindowClass,
CreateWindowAux, EventMask, InputFocus, PropMode, Visualid, Window as XWindow, WindowClass,
};
use x11rb::wrapper::ConnectionExt as _;
use x11rb::CURRENT_TIME;

use super::XcbConnection;
use crate::{
Expand Down Expand Up @@ -104,6 +105,7 @@ pub(crate) struct WindowInner {
mouse_cursor: Cell<MouseCursor>,

pub(crate) close_requested: Cell<bool>,
pub(crate) is_focused: Cell<bool>,
}

pub struct Window<'a> {
Expand Down Expand Up @@ -291,6 +293,7 @@ impl<'a> Window<'a> {
mouse_cursor: Cell::new(MouseCursor::default()),

close_requested: Cell::new(false),
is_focused: false.into(),

#[cfg(feature = "opengl")]
gl_context,
Expand Down Expand Up @@ -333,12 +336,17 @@ impl<'a> Window<'a> {
self.inner.close_requested.set(true);
}

pub fn has_focus(&mut self) -> bool {
unimplemented!()
pub fn has_focus(&self) -> bool {
self.inner.is_focused.get()
}

pub fn focus(&mut self) {
unimplemented!()
pub fn focus(&self) {
let _ = self.inner.xcb_connection.conn.set_input_focus(
InputFocus::POINTER_ROOT,
self.inner.window_id,
CURRENT_TIME,
);
let _ = self.inner.xcb_connection.conn.flush();
}

pub fn resize(&mut self, size: Size) {
Expand Down