Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(launcher): open new window on middle-click #814

Merged
merged 2 commits into from
Dec 18, 2024
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
5 changes: 3 additions & 2 deletions docs/modules/Launcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

Windows-style taskbar that displays running windows, grouped by program.
Hovering over a program with multiple windows open shows a popup with each window.
Clicking an icon/popup item focuses or launches the program.
Left clicking an icon/popup item focuses the program if it has any open instances or otherwise launches a new instance of the program.
Middle clicking an icon always launches a new instance of the program.
Optionally displays a launchable set of favourites.

![Screenshot showing several open applications, including a popup showing multiple terminal windows.](https://f.jstanger.dev/github/ironbar/launcher.png)
Expand Down Expand Up @@ -113,4 +114,4 @@ start:
| `.popup-launcher` | Popup container |
| `.popup-launcher .popup-item` | Window button in popup |

For more information on styling, please see the [styling guide](styling-guide).
For more information on styling, please see the [styling guide](styling-guide).
28 changes: 18 additions & 10 deletions src/modules/launcher/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::modules::launcher::{ItemEvent, LauncherUpdate};
use crate::modules::ModuleUpdateEvent;
use crate::{read_lock, try_send};
use glib::Propagation;
use gtk::gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY};
use gtk::prelude::*;
use gtk::{Button, IconTheme, Image, Label, Orientation};
use indexmap::IndexMap;
Expand Down Expand Up @@ -201,20 +202,27 @@ impl ItemButton {
let app_id = item.app_id.clone();
let tx = controller_tx.clone();
let menu_state = menu_state.clone();
button.connect_clicked(move |button| {
// lazy check :| TODO: Improve this
let style_context = button.style_context();
if style_context.has_class("open") {
let menu_state = read_lock!(menu_state);

if style_context.has_class("focused") && menu_state.num_windows == 1 {
try_send!(tx, ItemEvent::MinimizeItem(app_id.clone()));

button.connect_button_release_event(move |button, event| {
if event.button() == BUTTON_PRIMARY {
// lazy check :| TODO: Improve this
let style_context = button.style_context();
if style_context.has_class("open") {
let menu_state = read_lock!(menu_state);

if style_context.has_class("focused") && menu_state.num_windows == 1 {
JakeStanger marked this conversation as resolved.
Show resolved Hide resolved
try_send!(tx, ItemEvent::MinimizeItem(app_id.clone()));
} else {
try_send!(tx, ItemEvent::FocusItem(app_id.clone()));
}
} else {
try_send!(tx, ItemEvent::FocusItem(app_id.clone()));
try_send!(tx, ItemEvent::OpenItem(app_id.clone()));
}
} else {
} else if event.button() == BUTTON_MIDDLE {
try_send!(tx, ItemEvent::OpenItem(app_id.clone()));
}

Propagation::Proceed
});
}

Expand Down
Loading