Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
H3rmt committed Feb 3, 2024
1 parent d89a414 commit cca414e
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 75 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "window_switcher"
name = "hyprswitch"
description = "A CLI that allows switching between windows in Hyprland"
version = "0.2.1"
edition = "2021"
license = "MIT"
readme = "README.md"
documentation = "https://docs.rs/crate/window_switcher"
repository = "https://github.com/H3rmt/WindowSwitcher/"
keywords = ["hyprland", "hyprland"]
documentation = "https://docs.rs/crate/hyprswitch"
repository = "https://github.com/h3rmt/hyprswitch/"
keywords = ["hyprland"]
categories = ["command-line-utilities"]

[dependencies]
Expand Down
49 changes: 30 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,75 @@
# WindowSwitcher
# hyprswitch

[![crates.io](https://img.shields.io/crates/v/window_switcher.svg)](https://crates.io/crates/window_switcher)
[![Docs](https://docs.rs/built/badge.svg)](https://docs.rs/window_switcher)
[![Tests](https://github.com/H3rmt/WindowSwitcher/actions/workflows/rust.yml/badge.svg)](https://github.com/H3rmt/WindowSwitcher/actions/workflows/rust.yml)
[![crates.io](https://img.shields.io/crates/v/hyprswitch.svg)](https://crates.io/crates/hyprswitch)
[![Docs](https://docs.rs/built/badge.svg)](https://docs.rs/hyprswitch)
[![Tests](https://github.com/h3rmt/hyprswitch/actions/workflows/rust.yml/badge.svg)](https://github.com/h3rmt/hyprswitch/actions/workflows/rust.yml)

A small rust CLI tool to switch between windows in hyperland.

It can switch through all windows or only windows of same class(= application) in regular or reverse order.
A rust CLI/GUI to switch between windows in [hyperland](https://github.com/https://github.com/hyprwm/Hyprland)

It can switch through all windows or only windows of same class(= application) in regular or reverse order, and has a
GNOME-like gui.

# Installation

`
cargo install window_switcher
cargo install hyprswitch
`

# Usage

Once the binary is installed, you can modify your `~/.config/hypr/hyprland.conf`.

Here are some samples:

- simple config

```
# switches to next window
bind = ALT, TAB, exec, $HOME/.cargo/bin/window_switcher
bind = ALT, TAB, exec, $HOME/.cargo/bin/hyprswitch
# switches to next window of same class
bind = ALT CTRL, TAB, exec, $HOME/.cargo/bin/window_switcher --same-class
bind = ALT CTRL, TAB, exec, $HOME/.cargo/bin/hyprswitch --same-class
# switches to next window in workspace
bind = SUPER, TAB, exec, $HOME/.cargo/bin/window_switcher --stay-workspace
bind = SUPER, TAB, exec, $HOME/.cargo/bin/hyprswitch --stay-workspace
```

- with reverse binds

```
# switches to next window
bind = ALT, TAB, exec, $HOME/.cargo/bin/window_switcher
bind = ALT, TAB, exec, $HOME/.cargo/bin/hyprswitch
# switches to next window in reverse order
bind = ALT SHIFT, TAB, exec, $HOME/.cargo/bin/window_switcher --reverse
bind = ALT SHIFT, TAB, exec, $HOME/.cargo/bin/hyprswitch --reverse
# switches to next window in workspace
bind = SUPER, TAB, exec, $HOME/.cargo/bin/window_switcher --stay-workspace
bind = SUPER, TAB, exec, $HOME/.cargo/bin/hyprswitch --stay-workspace
# switches to next window in workspace in reverse order
bind = SUPER, TAB, exec, $HOME/.cargo/bin/window_switcher --stay-workspace --reverse
bind = SUPER, TAB, exec, $HOME/.cargo/bin/hyprswitch --stay-workspace --reverse
# switches to next window of same class
bind = ALT CTRL, TAB, exec, $HOME/.cargo/bin/window_switcher --same-class
bind = ALT CTRL, TAB, exec, $HOME/.cargo/bin/hyprswitch --same-class
# switches to next window of same class in reverse order
bind = ALT CTRL SHIFT, TAB, exec, $HOME/.cargo/bin/window_switcher --reverse --same-class
bind = ALT CTRL SHIFT, TAB, exec, $HOME/.cargo/bin/hyprswitch --reverse --same-class
```

The script accepts 5 parameters:.

- `--same-class` Switch between windows of same class (type)
- `--reverse` Reverse the order of the windows
- `--stay-workspace` Restrict cycling of windows to current workspace
- `--ignore-workspace` Ignore workspaces and sort like one big workspace for each monitor
- `--ignore-monitor` Ignore monitors and sort like one big monitor, [workspaces must have offset of 10 for each monitor ](#ignore-monitors-flag)
- `--ignore-monitor` Ignore monitors and sort like one big
monitor, [workspaces must have offset of 10 for each monitor ](#ignore-monitors-flag)
- `--vertical-workspaces` will treat workspaces as vertical aligned (used with `--ignore-workspace`)

# Sorting of windows

See [tests](/tests) for more details on how windows get sorted

```
Expand All @@ -76,6 +83,7 @@ See [tests](/tests) for more details on how windows get sorted
7 +------+ +------+
1 2 3 4
```

```
Monitor 1
Workspace 1 Workspace 2
Expand All @@ -88,6 +96,7 @@ See [tests](/tests) for more details on how windows get sorted
7 +------+ +------+ | +------+ +------+
1 2 3 4 1 2 3 4
```

```
1 3 5 6 8 10 11 12
+----------------------------------------+
Expand All @@ -106,8 +115,10 @@ See [tests](/tests) for more details on how windows get sorted
```

### Ignore monitors flag

This flag requires that workspaces have an offset of 10 for each monitor. (TODO, make this configurable)

This means that if you have 2 monitors, the workspaces on the second monitor must start at 11 if the first workspace on the first monitor is 1.
This means that if you have 2 monitors, the workspaces on the second monitor must start at 11 if the first workspace on
the first monitor is 1.

this can be configured in `~/.config/hypr/hyprland.conf` (https://wiki.hyprland.org/Configuring/Workspace-Rules/)
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Debug;

use clap::Parser;

use window_switcher::Info;
use hyprswitch::Info;

#[derive(Parser, Debug, Clone, Copy)]
#[command(author, version, about, long_about = None)]
Expand Down
2 changes: 1 addition & 1 deletion src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tokio::net::{UnixListener, UnixStream};

use crate::Info;

const PATH: &str = "/tmp/window_switcher.sock";
const PATH: &str = "/tmp/hyprswitch.sock";

pub async fn daemon_running() -> bool {
// check if socket exists and socket is open
Expand Down
2 changes: 1 addition & 1 deletion src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ pub fn start_gui(
do_toast: bool,
) {
let application = Application::builder()
.application_id("com.github.h3rmt.window_switcher")
.application_id("com.github.h3rmt.hyprswitch")
// .flags(ApplicationFlags::IS_LAUNCHER)
.build();

Expand Down
40 changes: 20 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Parser;
use hyprland::data::Client;

use window_switcher::handle;
use hyprswitch::handle;

use crate::cli::Args;

Expand All @@ -11,22 +11,22 @@ mod cli;
/// # Usage
///
/// * Switch between windows of same class
/// * `window_switcher --same-class`
/// * `hyprswitch --same-class`
/// * Switch backwards
/// * `window_switcher --reverse`
/// * `hyprswitch --reverse`
///
/// ## Special
///
/// * Cycles through window on current workspace
/// * `window_switcher --stay-workspace`
/// * `hyprswitch --stay-workspace`
///
/// * Ignore workspaces and sort like one big workspace
/// * `window_switcher --ignore-workspaces`
/// * `hyprswitch --ignore-workspaces`
/// * Ignore monitors and sort like one big monitor
/// * `window_switcher --ignore-monitors`
/// * `hyprswitch --ignore-monitors`
///
/// * Display workspaces vertically on monitors
/// * `window_switcher --vertical-workspaces`
/// * `hyprswitch --vertical-workspaces`
///
fn main() {
let cli = Args::parse();
Expand All @@ -36,15 +36,15 @@ fn main() {
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");

rt.block_on(async {
use window_switcher::daemon;
use hyprswitch::daemon;

if !daemon::daemon_running().await {
if cli.verbose {
println!("Starting daemon");
}

#[cfg(feature = "gui")]
let latest: window_switcher::Share;
let latest: hyprswitch::Share;

#[cfg(feature = "gui")] {
use tokio::sync::Mutex;
Expand All @@ -55,7 +55,7 @@ fn main() {
Mutex::new((cli.into(), handle::collect_data(cli.into())
.map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to collect data: {}", _e));
}
Expand All @@ -70,12 +70,12 @@ fn main() {
let latest = latest.clone();

std::thread::spawn(move || {
use window_switcher::gui;
use hyprswitch::gui;
gui::start_gui(
move |next_client: Client| {
handle::execute(&next_client, cli.dry_run).map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to focus next client: {}", _e));
}
Expand All @@ -98,7 +98,7 @@ fn main() {
latest_data| async move {
let data = handle::collect_data(cli.into()).map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to collect data: {}", _e));
}
Expand All @@ -117,7 +117,7 @@ fn main() {

let next_client = handle::find_next(info, clients, active).map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to handle command: {}", _e));
}
Expand All @@ -126,7 +126,7 @@ fn main() {

handle::execute(&next_client, cli.dry_run).map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to focus next client: {}", _e));
}
Expand All @@ -144,7 +144,7 @@ fn main() {
})
.await.map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to start daemon: {}", _e));
}
Expand All @@ -157,7 +157,7 @@ fn main() {

daemon::send_command(cli.into()).await.map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to send command to daemon: {}", _e));
}
Expand All @@ -169,7 +169,7 @@ fn main() {

let data = handle::collect_data(cli.into()).map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to collect data: {}", _e));
}
Expand All @@ -178,7 +178,7 @@ fn main() {

let next_client = handle::find_next(cli.into(), data.clients, data.active).map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to find next client: {}", _e));
}
Expand All @@ -187,7 +187,7 @@ fn main() {

handle::execute(&next_client, cli.dry_run).map_err(|_e| {
#[cfg(feature = "toast")] {
use window_switcher::toast::toast;
use hyprswitch::toast::toast;
if cli.toast {
toast(&format!("Failed to focus next client: {}", _e));
}
Expand Down
4 changes: 2 additions & 2 deletions src/toast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use notify_rust::Notification;

pub fn toast(message: &str) {
Notification::new()
.summary("Error in window_switcher")
.summary("Error in hyprswitch")
.body(message)
.appname("window_switcher")
.appname("hyprswitch")
.timeout(0)
.show().expect("Failed to send notification");
}
4 changes: 2 additions & 2 deletions tests/many_windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::time::Instant;

use hyprland::shared::WorkspaceId;

use window_switcher::{MonitorData, WorkspaceData};
use window_switcher::sort::{sort_clients, update_clients};
use hyprswitch::{MonitorData, WorkspaceData};
use hyprswitch::sort::{sort_clients, update_clients};

use crate::common::{create_svg_from_client_tests, function, is_sorted, MockClient};

Expand Down
Loading

0 comments on commit cca414e

Please sign in to comment.