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
48 changes: 25 additions & 23 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ use glib::object::Cast;
use glib::timeout_add_local_once;
use glib_macros::{clone, closure};
use gtk4::prelude::{BoxExt, ButtonExt, GObjectPropertyExpressionExt, GtkWindowExt, WidgetExt};
use gtk4::{EventControllerKey, GestureClick, PropagationPhase};
use gtk4::{EventControllerKey, EventControllerMotion, GestureClick, PropagationPhase};
use gtk4_layer_shell::{KeyboardMode, LayerShell};
use libadwaita::prelude::AdwApplicationWindowExt;
use std::sync::Arc;
use std::time::Duration;
use wleave::cli_opt::{ButtonLayout, Protocol};
use wleave::units::{AspectRatio, LengthArgs, LengthDimension};

fn do_exit(window: &WleaveWindow, _service_mode: bool) {
window.close();
fn do_exit(window: &WleaveWindow, service_mode: bool) {
if service_mode {
window.set_visible(false);
} else {
window.close();
}
}

fn on_option(
Expand All @@ -34,27 +38,15 @@ fn on_option(

let command = command.clone();

window.connect_hide(clone!(
#[strong]
command,
move |window| {
timeout_add_local_once(
Duration::from_millis(delay_ms.into()),
clone!(
#[strong]
command,
#[weak_allow_none]
window,
move || {
run_command(command);
window.inspect(move |w| do_exit(w, service_mode));
}
),
);
}
));

window.set_visible(false);

timeout_add_local_once(Duration::from_millis(delay_ms.into()), move || {
run_command(command);

if !service_mode {
do_exit(&window, service_mode);
}
});
}

fn handle_key(
Expand Down Expand Up @@ -272,6 +264,16 @@ pub fn create_app(config: &Arc<AppConfig>, app: &libadwaita::Application) -> Wle
.cursor(&gdk4::Cursor::from_name("pointer", None).expect("pointer cursor not found"))
.build();

let motion_controller = EventControllerMotion::new();
motion_controller.connect_enter(clone!(
#[weak]
button,
move |_, _, _| {
button.grab_focus();
}
));
button.add_controller(motion_controller);

let overlay = gtk4::Overlay::builder().vexpand(true).hexpand(true).build();

if config.show_keybinds {
Expand Down
14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ mod layout;
mod paintable;

use clap::Parser;
use glib::clone;
use glib::{clone, object::Cast};
use std::sync::Arc;
use tracing::{Level, error};
use tracing_subscriber::EnvFilter;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

use crate::app::create_app;
use crate::app::{create_app, window::WleaveWindow};
use crate::config::{AppConfig, load_config, load_css, merge_with_args};
use gtk4::gdk::Display;
use gtk4::prelude::*;
Expand Down Expand Up @@ -57,6 +57,16 @@ fn entry_point(config: Arc<AppConfig>) -> miette::Result<()> {
app.connect_activate(move |app| {
let _ = &hold_guard;

if config.service
&& let Some(app_window) = app
.windows()
.into_iter()
.find_map(|window| window.downcast::<WleaveWindow>().ok())
{
app_window.present();
return;
}

let app_window = create_app(&config, app);
app_window.present();
});
Expand Down
5 changes: 2 additions & 3 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ button label.keybind {
font-family: monospace;
}

button:hover label.keybind, button:focus label.keybind {
button:focus label.keybind {
opacity: 1;
}

button:focus,
button:hover {
button:focus {
background-color: color-mix(in srgb, var(--accent-bg-color), var(--view-bg-color));
}

Expand Down