Skip to content
Merged
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: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ libc = "0.2.180"
log = "0.4.29"
minreq = { version = "2.14.1", features = ["https"] }
objc2 = "0.6.3"
objc2-app-kit = { version = "0.3.2", features = ["NSImage"] }
objc2-app-kit = { version = "0.3.2", features = ["NSImage", "NSScreen"] }
objc2-application-services = { version = "0.3.2", default-features = false, features = ["HIServices", "Processes"] }
objc2-core-foundation = "0.3.2"
objc2-core-graphics = { version = "0.3.2", features = ["CGEvent"] }
Expand Down
34 changes: 34 additions & 0 deletions src/app/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,40 @@ impl App {
]
}

/// Window tiling actions (12 positions)
pub fn window_apps() -> Vec<App> {
use crate::platform::macos::window::TilePosition;

let icons = icns_data_to_handle(ICNS_ICON.to_vec());

let actions: &[(&str, TilePosition)] = &[
("Left Half", TilePosition::LeftHalf),
("Right Half", TilePosition::RightHalf),
("Top Half", TilePosition::TopHalf),
("Bottom Half", TilePosition::BottomHalf),
("Top Left Quarter", TilePosition::TopLeft),
("Top Right Quarter", TilePosition::TopRight),
("Bottom Left Quarter", TilePosition::BottomLeft),
("Bottom Right Quarter", TilePosition::BottomRight),
("Left Third", TilePosition::LeftThird),
("Center Third", TilePosition::CenterThird),
("Right Third", TilePosition::RightThird),
("Maximize", TilePosition::Maximize),
];

actions
.iter()
.map(|(name, pos)| App {
ranking: 0,
open_command: AppCommand::Function(Function::TileWindow(pos.clone())),
desc: "Window Tiling".to_string(),
icons: icons.clone(),
display_name: name.to_string(),
search_name: name.to_lowercase(),
})
.collect()
}

/// This renders the app into an iced element, allowing it to be displayed in the search results
pub fn render(
self,
Expand Down
2 changes: 2 additions & 0 deletions src/app/tile/elm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub fn new(hotkeys: Hotkeys, config: &Config) -> (Tile, Task<Message>) {

options.extend(App::basic_apps());
info!("Loaded basic apps / default apps");
options.extend(App::window_apps());
info!("Loaded window tiling apps");
options.par_sort_by_key(|x| x.display_name.len());
let options = AppIndex::from_apps(options);

Expand Down
9 changes: 9 additions & 0 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
}

Message::RunFunction(command) => {
if let Function::TileWindow(pos) = &command {
if let Some(pid) = tile.frontmost.as_ref().map(|a| a.processIdentifier()) {
let ok = crate::platform::macos::window::tile_focused_window(pid, pos);
if !ok && tile.config.haptic_feedback {
perform_haptic(HapticPattern::Alignment);
}
}
}
command.execute(&tile.config);
let page_task = match tile.page {
Page::Settings => Task::done(Message::SwitchToPage(Page::Main)),
Expand Down Expand Up @@ -615,6 +623,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
new_options.extend(tile.config.shells.iter().map(|x| x.to_app()));
new_options.extend(tile.config.modes.to_apps());
new_options.extend(App::basic_apps());
new_options.extend(App::window_apps());
new_options.par_sort_by_key(|x| x.display_name.len());
tile.options = AppIndex::from_apps(new_options);

Expand Down
5 changes: 5 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum Function {
GoogleSearch(String),
Calculate(Expr),
Quit,
TileWindow(crate::platform::macos::window::TilePosition),
}

impl Function {
Expand Down Expand Up @@ -122,6 +123,10 @@ impl Function {
},

Function::Quit => std::process::exit(0),

// TileWindow is intercepted in the RunFunction handler which has
// access to the frontmost PID; nothing to do here.
Function::TileWindow(_) => {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark it with unreachable!() please.

}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/platform/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod events;
pub mod haptics;
pub mod launching;
pub mod urlscheme;
pub mod window;

use iced::wgpu::rwh::WindowHandle;

Expand Down
Loading
Loading