Add onmiddleclick and onrightclick to button

This commit is contained in:
elkowar 2021-05-09 13:57:24 +02:00
parent 3b60b64c34
commit b1cb74d386
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F
2 changed files with 112 additions and 6 deletions

101
Cargo.lock generated
View file

@ -41,6 +41,12 @@ version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b"
[[package]]
name = "anymap"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.5.2" version = "0.5.2"
@ -221,6 +227,27 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "crossbeam-channel"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278"
dependencies = [
"autocfg",
"cfg-if",
"lazy_static",
]
[[package]] [[package]]
name = "ctor" name = "ctor"
version = "0.1.20" version = "0.1.20"
@ -308,7 +335,6 @@ dependencies = [
"gtk", "gtk",
"gtk-layer-shell", "gtk-layer-shell",
"gtk-layer-shell-sys", "gtk-layer-shell-sys",
"inotify",
"itertools 0.10.0", "itertools 0.10.0",
"lazy_static", "lazy_static",
"libc", "libc",
@ -316,6 +342,7 @@ dependencies = [
"maplit", "maplit",
"nix", "nix",
"nom", "nom",
"notify",
"num", "num",
"pretty_assertions", "pretty_assertions",
"pretty_env_logger", "pretty_env_logger",
@ -346,6 +373,37 @@ dependencies = [
"syn 1.0.71", "syn 1.0.71",
] ]
[[package]]
name = "filetime"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"winapi",
]
[[package]]
name = "fsevent"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97f347202c95c98805c216f9e1df210e8ebaec9fdb2365700a43c10797a35e63"
dependencies = [
"bitflags",
"fsevent-sys",
]
[[package]]
name = "fsevent-sys"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a29c77f1ca394c3e73a9a5d24cfcabb734682d9634fc398f2204a63c994120"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "funty" name = "funty"
version = "1.1.0" version = "1.1.0"
@ -813,10 +871,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d19f57db1baad9d09e43a3cd76dcf82ebdafd37d75c9498b87762dba77c93f15" checksum = "d19f57db1baad9d09e43a3cd76dcf82ebdafd37d75c9498b87762dba77c93f15"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"futures-core",
"inotify-sys", "inotify-sys",
"libc", "libc",
"tokio",
] ]
[[package]] [[package]]
@ -972,6 +1028,25 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "notify"
version = "5.0.0-pre.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebe7699a0f8c5759450716ee03d231685c22b4fe8f406c42c22e0ad94d40ce7"
dependencies = [
"anymap",
"bitflags",
"crossbeam-channel",
"filetime",
"fsevent",
"fsevent-sys",
"inotify",
"libc",
"mio",
"walkdir",
"winapi",
]
[[package]] [[package]]
name = "ntapi" name = "ntapi"
version = "0.3.6" version = "0.3.6"
@ -1429,6 +1504,15 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.1.0" version = "1.1.0"
@ -1780,6 +1864,17 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "walkdir"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [
"same-file",
"winapi",
"winapi-util",
]
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.9.0+wasi-snapshot-preview1" version = "0.9.0+wasi-snapshot-preview1"

View file

@ -356,16 +356,27 @@ fn build_gtk_input(bargs: &mut BuilderArgs) -> Result<gtk::Entry> {
fn build_gtk_button(bargs: &mut BuilderArgs) -> Result<gtk::Button> { fn build_gtk_button(bargs: &mut BuilderArgs) -> Result<gtk::Button> {
let gtk_widget = gtk::Button::new(); let gtk_widget = gtk::Button::new();
let on_click_handler_id: Rc<RefCell<Option<glib::SignalHandlerId>>> = Rc::new(RefCell::new(None)); let on_click_handler_id: Rc<RefCell<Option<glib::SignalHandlerId>>> = Rc::new(RefCell::new(None));
resolve_block!(bargs, gtk_widget, { resolve_block!(bargs, gtk_widget, {
// @prop onclick - a command that get's run when the button is clicked // @prop onclick - a command that get's run when the button is clicked
prop(onclick: as_string) { // @prop onmiddleclick - a command that get's run when the button is middleclicked
// @prop onrightclick - a command that get's run when the button is rightclicked
prop(onclick: as_string = "", onmiddleclick: as_string = "", onrightclick: as_string = "") {
gtk_widget.add_events(gdk::EventMask::ENTER_NOTIFY_MASK); gtk_widget.add_events(gdk::EventMask::ENTER_NOTIFY_MASK);
let old_id = on_click_handler_id.replace(Some( let old_id = on_click_handler_id.replace(Some(
gtk_widget.connect_clicked(move |_| run_command(&onclick, "")) gtk_widget.connect_button_press_event(move |_, evt| {
match evt.get_button() {
1 => run_command(&onclick, ""),
2 => run_command(&onmiddleclick, ""),
3 => run_command(&onrightclick, ""),
_ => {},
}
gtk::Inhibit(false)
})
)); ));
old_id.map(|id| gtk_widget.disconnect(id)); old_id.map(|id| gtk_widget.disconnect(id));
} }
}); });
Ok(gtk_widget) Ok(gtk_widget)
} }