Add Ctl Socket, iterate on Idling daemon, update sysinfo crate, start on run menu
This commit is contained in:
77
src/ui/run_menu.rs
Normal file
77
src/ui/run_menu.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use gtk::prelude::{BoxExt, GtkWindowExt, WidgetExt};
|
||||
use gtk::{Align, Application, ApplicationWindow, Orientation, PolicyType, gdk};
|
||||
use gtk4_layer_shell::{KeyboardMode, Layer, LayerShell};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RunMenu {
|
||||
window: ApplicationWindow,
|
||||
}
|
||||
|
||||
impl RunMenu {
|
||||
pub fn create(application: Application) -> Self {
|
||||
let window = gtk::ApplicationWindow::builder()
|
||||
.application(&application)
|
||||
.title("JmbRunMenu")
|
||||
.default_width(500)
|
||||
.default_height(300)
|
||||
.css_classes(["run-menu"])
|
||||
.build();
|
||||
|
||||
window.init_layer_shell();
|
||||
window.set_layer(Layer::Overlay);
|
||||
window.set_halign(Align::Center);
|
||||
window.set_valign(Align::Center);
|
||||
window.set_size_request(500, 300);
|
||||
window.set_keyboard_mode(KeyboardMode::Exclusive);
|
||||
|
||||
let v_box = gtk::Box::new(Orientation::Vertical, 0);
|
||||
|
||||
let entry = gtk::Entry::new();
|
||||
entry.add_css_class("entry");
|
||||
|
||||
let scrolled = gtk::ScrolledWindow::new();
|
||||
scrolled.set_policy(PolicyType::Never, PolicyType::Automatic);
|
||||
scrolled.set_vexpand(true);
|
||||
scrolled.set_valign(Align::Fill);
|
||||
|
||||
let content_box = gtk::Box::new(Orientation::Vertical, 0);
|
||||
content_box.add_css_class("content-box");
|
||||
|
||||
for _ in 0..10 {
|
||||
let label = gtk::Label::new(Some("Test"));
|
||||
content_box.append(&label);
|
||||
}
|
||||
|
||||
scrolled.set_child(Some(&content_box));
|
||||
|
||||
v_box.append(&entry);
|
||||
v_box.append(&scrolled);
|
||||
|
||||
window.set_child(Some(&v_box));
|
||||
|
||||
let window_clone = window.clone();
|
||||
let instance = Self {
|
||||
window: window_clone,
|
||||
};
|
||||
let instance_clone = instance.clone();
|
||||
let key_controller = gtk::EventControllerKey::new();
|
||||
key_controller.connect_key_pressed(move |_, key, _, _| {
|
||||
if key == gdk::Key::Escape {
|
||||
instance_clone.hide();
|
||||
glib::Propagation::Stop
|
||||
} else {
|
||||
glib::Propagation::Proceed
|
||||
}
|
||||
});
|
||||
window.add_controller(key_controller);
|
||||
instance
|
||||
}
|
||||
|
||||
pub fn hide(&self) {
|
||||
self.window.set_visible(false);
|
||||
}
|
||||
|
||||
pub fn show(&self) {
|
||||
self.window.present();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user