Reworked runner position configuration to allow for far more flexibility
This commit is contained in:
@@ -155,7 +155,6 @@ Anyrun requires plugins to function, as they provide the results for input. The
|
|||||||
- Search and run system & user specific desktop entries.
|
- Search and run system & user specific desktop entries.
|
||||||
- [Symbols](plugins/symbols/README.md)
|
- [Symbols](plugins/symbols/README.md)
|
||||||
- Search unicode symbols.
|
- Search unicode symbols.
|
||||||
- [User defined symbols](plugins/symbols/README.md#User-defined-symbols)
|
|
||||||
- [Rink](plugins/rink/README.md)
|
- [Rink](plugins/rink/README.md)
|
||||||
- Calculator & unit conversion.
|
- Calculator & unit conversion.
|
||||||
- [Shell](plugins/shell/README.md)
|
- [Shell](plugins/shell/README.md)
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
use proc_macro::{Span, TokenStream};
|
use proc_macro::{Span, TokenStream};
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{parse_macro_input, parse_quote, Attribute, Ident, ReturnType, Type};
|
use syn::{parse_macro_input, parse_quote, Ident, ReturnType, Type};
|
||||||
|
|
||||||
/// The function to handle the selection of an item. Takes a `Match` as its first argument, and the second argument can be one of:
|
/// The function to handle the selection of an item. Takes a `Match` as its first argument, and the second argument can be one of:
|
||||||
/// - &T
|
/// - &T
|
||||||
|
@@ -20,9 +20,10 @@ use wl_clipboard_rs::copy;
|
|||||||
#[anyrun_macros::config_args]
|
#[anyrun_macros::config_args]
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
|
x: RelativeNum,
|
||||||
|
y: RelativeNum,
|
||||||
width: RelativeNum,
|
width: RelativeNum,
|
||||||
vertical_offset: RelativeNum,
|
height: RelativeNum,
|
||||||
position: Position,
|
|
||||||
plugins: Vec<PathBuf>,
|
plugins: Vec<PathBuf>,
|
||||||
hide_icons: bool,
|
hide_icons: bool,
|
||||||
hide_plugin_info: bool,
|
hide_plugin_info: bool,
|
||||||
@@ -36,9 +37,10 @@ struct Config {
|
|||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
width: RelativeNum::Absolute(800),
|
x: RelativeNum::Fraction(0.5),
|
||||||
vertical_offset: RelativeNum::Absolute(0),
|
y: RelativeNum::Absolute(0),
|
||||||
position: Position::Top,
|
width: RelativeNum::Fraction(0.4),
|
||||||
|
height: RelativeNum::Absolute(0),
|
||||||
plugins: vec![
|
plugins: vec![
|
||||||
"libapplications.so".into(),
|
"libapplications.so".into(),
|
||||||
"libsymbols.so".into(),
|
"libsymbols.so".into(),
|
||||||
@@ -71,6 +73,15 @@ enum RelativeNum {
|
|||||||
Fraction(f32),
|
Fraction(f32),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RelativeNum {
|
||||||
|
fn to_val(&self, val: u32) -> i32 {
|
||||||
|
match self {
|
||||||
|
RelativeNum::Absolute(num) => *num,
|
||||||
|
RelativeNum::Fraction(frac) => (frac * val as f32) as i32,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<&str> for RelativeNum {
|
impl From<&str> for RelativeNum {
|
||||||
fn from(value: &str) -> Self {
|
fn from(value: &str) -> Self {
|
||||||
let (ty, val) = value.split_once(':').expect("Invalid RelativeNum value");
|
let (ty, val) = value.split_once(':').expect("Invalid RelativeNum value");
|
||||||
@@ -584,10 +595,14 @@ fn activate(app: >k::Application, runtime_data: Rc<RefCell<RuntimeData>>) {
|
|||||||
let main_list = main_list.clone();
|
let main_list = main_list.clone();
|
||||||
|
|
||||||
configure_once.call_once(move || {
|
configure_once.call_once(move || {
|
||||||
let width = match runtime_data.borrow().config.width {
|
{
|
||||||
RelativeNum::Absolute(width) => width,
|
let runtime_data = runtime_data.borrow();
|
||||||
RelativeNum::Fraction(fraction) => (event.size().0 as f32 * fraction) as i32,
|
|
||||||
};
|
let width = runtime_data.config.width.to_val(event.size().0);
|
||||||
|
let x = runtime_data.config.x.to_val(event.size().0) - width / 2;
|
||||||
|
let height = runtime_data.config.height.to_val(event.size().1);
|
||||||
|
let y = runtime_data.config.y.to_val(event.size().1) - height / 2;
|
||||||
|
|
||||||
// The GtkFixed widget is used for absolute positioning of the main box
|
// The GtkFixed widget is used for absolute positioning of the main box
|
||||||
let fixed = gtk::Fixed::builder().build();
|
let fixed = gtk::Fixed::builder().build();
|
||||||
let main_vbox = gtk::Box::builder()
|
let main_vbox = gtk::Box::builder()
|
||||||
@@ -595,38 +610,25 @@ fn activate(app: >k::Application, runtime_data: Rc<RefCell<RuntimeData>>) {
|
|||||||
.halign(gtk::Align::Center)
|
.halign(gtk::Align::Center)
|
||||||
.vexpand(false)
|
.vexpand(false)
|
||||||
.width_request(width)
|
.width_request(width)
|
||||||
|
.height_request(height)
|
||||||
.name(style_names::MAIN)
|
.name(style_names::MAIN)
|
||||||
.build();
|
.build();
|
||||||
main_vbox.add(&entry);
|
main_vbox.add(&entry);
|
||||||
|
|
||||||
// Display the error message
|
// Display the error message
|
||||||
if !runtime_data.borrow().error_label.is_empty() {
|
if !runtime_data.error_label.is_empty() {
|
||||||
main_vbox.add(
|
main_vbox.add(
|
||||||
>k::Label::builder()
|
>k::Label::builder()
|
||||||
.label(&format!(
|
.label(&format!(
|
||||||
r#"<span foreground="red">{}</span>"#,
|
r#"<span foreground="red">{}</span>"#,
|
||||||
runtime_data.borrow().error_label
|
runtime_data.error_label
|
||||||
))
|
))
|
||||||
.use_markup(true)
|
.use_markup(true)
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let vertical_offset = match runtime_data.borrow().config.vertical_offset {
|
fixed.put(&main_vbox, x, y);
|
||||||
RelativeNum::Absolute(offset) => offset,
|
|
||||||
RelativeNum::Fraction(fraction) => (event.size().1 as f32 * fraction) as i32,
|
|
||||||
};
|
|
||||||
|
|
||||||
fixed.put(
|
|
||||||
&main_vbox,
|
|
||||||
(event.size().0 as i32 - width) / 2,
|
|
||||||
match runtime_data.borrow().config.position {
|
|
||||||
Position::Top => vertical_offset,
|
|
||||||
Position::Center => {
|
|
||||||
(event.size().1 as i32 - entry.allocated_height()) / 2 + vertical_offset
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
window.add(&fixed);
|
window.add(&fixed);
|
||||||
window.show_all();
|
window.show_all();
|
||||||
|
|
||||||
@@ -634,6 +636,7 @@ fn activate(app: >k::Application, runtime_data: Rc<RefCell<RuntimeData>>) {
|
|||||||
main_vbox.add(&main_list);
|
main_vbox.add(&main_list);
|
||||||
main_list.show();
|
main_list.show();
|
||||||
entry.grab_focus(); // Grab the focus so typing is immediately accepted by the entry box
|
entry.grab_focus(); // Grab the focus so typing is immediately accepted by the entry box
|
||||||
|
}
|
||||||
|
|
||||||
if runtime_data.borrow().config.show_results_immediately {
|
if runtime_data.borrow().config.show_results_immediately {
|
||||||
// Get initial matches
|
// Get initial matches
|
||||||
|
@@ -3,14 +3,17 @@ Config(
|
|||||||
// Absolute(n): The absolute value in pixels
|
// Absolute(n): The absolute value in pixels
|
||||||
// Fraction(n): A fraction of the width or height of the full screen (depends on exclusive zones and the settings related to them) window respectively
|
// Fraction(n): A fraction of the width or height of the full screen (depends on exclusive zones and the settings related to them) window respectively
|
||||||
|
|
||||||
// How wide the input box and results are.
|
// The horizontal position, adjusted so that Relative(0.5) always centers the runner
|
||||||
|
x: Relative(0.5),
|
||||||
|
|
||||||
|
// The vertical position, works the same as `x`
|
||||||
|
y: Absolute(0),
|
||||||
|
|
||||||
|
// The width of the runner
|
||||||
width: Absolute(800),
|
width: Absolute(800),
|
||||||
|
|
||||||
// Where Anyrun is located on the screen: Top, Center
|
// The minimum height of the runner, the runner will expand to fit all the entries
|
||||||
position: Top,
|
height: Absolute(0),
|
||||||
|
|
||||||
// How much the runner is shifted vertically
|
|
||||||
vertical_offset: Absolute(0),
|
|
||||||
|
|
||||||
// Hide match and plugin info icons
|
// Hide match and plugin info icons
|
||||||
hide_icons: false,
|
hide_icons: false,
|
||||||
|
Reference in New Issue
Block a user