Skip to content
Draft
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,320 changes: 2,168 additions & 152 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions twm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ derivative = "2.1.1"
log = "0.4"
syn = "1.0.38"
flexi_logger = "0.15"
iced = { git = "https://github.com/hecrj/iced", rev = "45778ed598c0d202f8e86c47a444fd671fb3abce" }
reqwest = { version = "0.10", features = ["blocking", "json"] }
winapi = { version = "0.3", features = ["winuser", "errhandlingapi", "impl-default", "shellapi", "windowsx", "shellscalingapi", "processthreadsapi", "psapi"] }
serde = "1.0"
Expand Down
7 changes: 4 additions & 3 deletions twm/src/bar.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use crate::{system::DisplayId, window::Window, AppState};
use crate::{SystemError, SystemResult};
use item::Item;
use crate::{SystemResult, SystemError};
use item_section::ItemSection;
use parking_lot::Mutex;

Expand Down Expand Up @@ -46,7 +46,7 @@ impl Bar {

None
}

pub fn change_height(&self, height: i32) -> SystemResult {
let nwin = self.window.get_native_window();
let mut rect = nwin.get_rect()?;
Expand All @@ -57,7 +57,8 @@ impl Bar {
rect.top = rect.bottom - height;
}

nwin.set_window_pos(rect, None, None).map_err(|e| SystemError::Unknown(e))
nwin.set_window_pos(rect, None, None)
.map_err(|e| SystemError::Unknown(e))
}
}

Expand Down
18 changes: 11 additions & 7 deletions twm/src/config/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ pub enum Action {

impl std::fmt::Display for Action {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(f, "{}", match self {
Self::Manage => "manage",
Self::Pin=> "pin",
Self::Validate => "validate",
Self::Ignore => "ignore",
})
write!(
f,
"{}",
match self {
Self::Manage => "manage",
Self::Pin => "pin",
Self::Validate => "validate",
Self::Ignore => "ignore",
}
)
}
}

Expand All @@ -31,7 +35,7 @@ impl std::str::FromStr for Action {
"pin" => Self::Pin,
"validate" => Self::Validate,
"ignore" => Self::Ignore,
x => return Err(format!("{} is not a valid action for a rule", x))
x => return Err(format!("{} is not a valid action for a rule", x)),
})
}
}
Expand Down
8 changes: 3 additions & 5 deletions twm/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
keyboardhook::InputEvent, bar::item_section::ItemSection, keybindings::keybinding::Keybinding, popup::Popup,
system::DisplayId, win_event_handler::win_event::WinEvent,
bar::item_section::ItemSection, keybindings::keybinding::Keybinding, keyboardhook::InputEvent,
popup::Popup, system::DisplayId, win_event_handler::win_event::WinEvent,
};
use crossbeam_channel::unbounded;
use crossbeam_channel::Receiver;
Expand All @@ -14,9 +14,7 @@ pub enum Event {
NewPopup(Popup),
UpdateKeybindings,
LuaRuntimeError(LuaError),
CallCallback {
idx: usize
},
CallCallback { idx: usize },
ToggleAppbar(DisplayId),
UpdateBarSections(DisplayId, ItemSection, ItemSection, ItemSection),
ChangeWorkspace(i32, bool),
Expand Down
21 changes: 11 additions & 10 deletions twm/src/event_handler/winevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,26 @@ pub fn handle(state: &mut AppState, ev: WinEvent) -> SystemResult {
}

// checking pinned of each grid
grids.iter()
.map(|g| g.id)
.collect::<Vec::<_>>()
.iter()
.for_each(|g_id| {
grids
.iter()
.map(|g| g.id)
.collect::<Vec<_>>()
.iter()
.for_each(|g_id| {
if let Some(window) = state.pinned.get(&ev.window.id.into(), Some(*g_id)) {
title = Some(window.title.clone());
grid_id = Some(*g_id);
}
});
});

// checking global pinned
if let Some(window) = state.pinned.get(&ev.window.id.into(), None) {
title = Some(window.title.clone());
}

// window is not already managed and the event isn't `Show`
if title.is_none() && ev.typ != WinEventType::Show(false) && ev.typ != WinEventType::Show(true) {
if title.is_none() && ev.typ != WinEventType::Show(false) && ev.typ != WinEventType::Show(true)
{
return Ok(());
}

Expand Down Expand Up @@ -70,9 +72,8 @@ pub fn handle(state: &mut AppState, ev: WinEvent) -> SystemResult {
win.cleanup()?;
state.get_current_display().refresh_grid(&state.config)?;
}
},
WinEventType::Hide
| WinEventType::Unminimize => {}
}
WinEventType::Hide | WinEventType::Unminimize => {}
};

Ok(())
Expand Down
17 changes: 12 additions & 5 deletions twm/src/event_handler/winevent/show.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{system::NativeWindow, system::SystemResult, AppState};
use crate::config::rule::Action as RuleAction;
use crate::{system::NativeWindow, system::SystemResult, AppState};
use log::{debug, error};

pub fn handle(state: &mut AppState, mut window: NativeWindow, force: bool) -> SystemResult {
Expand Down Expand Up @@ -33,15 +33,22 @@ pub fn handle(state: &mut AppState, mut window: NativeWindow, force: bool) -> Sy
let parent = window.get_parent_window();
let rule = window.rule.clone().unwrap_or_default();
let is_window_pinned = state.pinned.is_pinned(&window.id.into());
let should_manage = force || rule.action == RuleAction::Manage || rule.action == RuleAction::Pin ||
(rule.action == RuleAction::Validate && !too_small
&& parent.is_err() && window.should_manage() && grid_allows_managing);
let should_manage = force
|| rule.action == RuleAction::Manage
|| rule.action == RuleAction::Pin
|| (rule.action == RuleAction::Validate
&& !too_small
&& parent.is_err()
&& window.should_manage()
&& grid_allows_managing);

if should_manage && !is_window_pinned {
if rule.action == RuleAction::Pin {
if state.pinned.can_pin(&window) {
let additional_rules = state.additonal_rules.clone();
state.pinned.pin_window(window, None, &config, &additional_rules)?;
state
.pinned
.pin_window(window, None, &config, &additional_rules)?;
state.pinned.store(None);
}
} else {
Expand Down
22 changes: 19 additions & 3 deletions twm/src/keybindings.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use crate::{keyboardhook::{self, InputEvent}, config::Config, event::Event, popup::Popup, system, system::api, AppState};
use crate::{
config::Config,
event::Event,
keyboardhook::{self, InputEvent},
popup::Popup,
system,
system::api,
AppState,
};
use key::Key;
use keybinding::Keybinding;
use log::{debug, error, info};
use modifier::Modifier;
use std::collections::HashMap;
use num_traits::FromPrimitive;
use parking_lot::Mutex;
use std::collections::HashMap;
use std::{
fmt::Debug,
sync::atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -50,7 +58,15 @@ pub fn listen(state_arc: Arc<Mutex<AppState>>) -> Sender<KeybindingsMessage> {
}
}

if let InputEvent::KeyDown { key_code, shift, ctrl, win, lalt, ralt } = ev {
if let InputEvent::KeyDown {
key_code,
shift,
ctrl,
win,
lalt,
ralt,
} = ev
{
let mut modifiers = Modifier::empty();

if ctrl {
Expand Down
6 changes: 4 additions & 2 deletions twm/src/keybindings/key.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use strum_macros::{EnumString, Display, AsRefStr};
use strum_macros::{AsRefStr, Display, EnumString};
use winapi::um::winuser::*;

#[derive(Clone, Copy, FromPrimitive, ToPrimitive, PartialEq, EnumString, AsRefStr, Display, Debug)]
#[derive(
Clone, Copy, FromPrimitive, ToPrimitive, PartialEq, EnumString, AsRefStr, Display, Debug,
)]
#[allow(dead_code)]
pub enum Key {
Enter = 0x0D,
Expand Down
7 changes: 3 additions & 4 deletions twm/src/keyboardhook.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use winapi::shared::minwindef::LRESULT;
use winapi::shared::windef::HHOOK;
use winapi::um::winuser::{
CallNextHookEx, DispatchMessageW, PeekMessageW, UnhookWindowsHookEx, SetWindowsHookExW, TranslateMessage,
KBDLLHOOKSTRUCT, MSG, PM_REMOVE, WH_KEYBOARD_LL, WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN,
WM_SYSKEYUP,
CallNextHookEx, DispatchMessageW, PeekMessageW, SetWindowsHookExW, TranslateMessage,
UnhookWindowsHookEx, KBDLLHOOKSTRUCT, MSG, PM_REMOVE, WH_KEYBOARD_LL, WM_KEYDOWN, WM_KEYUP,
WM_SYSKEYDOWN, WM_SYSKEYUP,
};

use std::sync::mpsc::{channel, Receiver, RecvError, Sender};
Expand Down Expand Up @@ -193,7 +193,6 @@ unsafe extern "system" fn hook_cb(ncode: i32, wparam: usize, lparam: isize) -> L
}
}
}

}
CallNextHookEx(std::ptr::null_mut(), ncode, wparam, lparam)
}
5 changes: 2 additions & 3 deletions twm/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ pub fn setup() -> Result<(), Box<dyn std::error::Error>> {
{
logger = logger.log_to_file();
}

logger.start()
.expect("Failed to initialize logger");

logger.start().expect("Failed to initialize logger");

Ok(())
}
16 changes: 11 additions & 5 deletions twm/src/lua/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use mlua::{Error as LuaError, FromLua, Table, ToLua, Value};

use crate::{
bar::component::Component, config::rule::Action as RuleAction,
keybindings::keybinding::Keybinding, split_direction::SplitDirection,
keybindings::keybinding::KeybindingKind};
keybindings::keybinding::Keybinding, keybindings::keybinding::KeybindingKind,
split_direction::SplitDirection,
};
use crate::{bar::component::ComponentText, direction::Direction, system::SystemError};
use std::str::FromStr;

Expand All @@ -19,7 +20,9 @@ impl FromLua<'_> for Direction {
fn from_lua(lua_value: mlua::Value<'_>, lua: &'_ mlua::Lua) -> mlua::Result<Self> {
let mut raw_direction = String::from_lua(lua_value, lua)?.to_lowercase();

raw_direction.get_mut(0..1).map(|s| s.make_ascii_uppercase());
raw_direction
.get_mut(0..1)
.map(|s| s.make_ascii_uppercase());

Ok(Direction::from_str(&raw_direction).unwrap_or(Direction::Right))
}
Expand All @@ -39,7 +42,9 @@ impl FromLua<'_> for SplitDirection {
fn from_lua(lua_value: mlua::Value<'_>, lua: &'_ mlua::Lua) -> mlua::Result<Self> {
let mut raw_direction = String::from_lua(lua_value, lua)?.to_lowercase();

raw_direction.get_mut(0..1).map(|s| s.make_ascii_uppercase());
raw_direction
.get_mut(0..1)
.map(|s| s.make_ascii_uppercase());

Ok(SplitDirection::from_str(&raw_direction).unwrap_or(SplitDirection::Horizontal))
}
Expand All @@ -60,7 +65,8 @@ impl ToLua<'_> for Keybinding {
impl FromLua<'_> for Keybinding {
fn from_lua(lua_value: Value<'_>, lua: &'_ mlua::Lua) -> mlua::Result<Self> {
let tbl = Table::from_lua(lua_value, lua)?;
let mut kb = Keybinding::from_str(&tbl.get::<_, String>("key")?).map_err(|e| LuaError::RuntimeError(e.to_string()))?;
let mut kb = Keybinding::from_str(&tbl.get::<_, String>("key")?)
.map_err(|e| LuaError::RuntimeError(e.to_string()))?;

kb.callback_id = tbl.get::<_, usize>("callback_id")?;

Expand Down
Loading