Skip to content

Commit

Permalink
Merge pull request #7 from luxluth/gtk-layer-shell
Browse files Browse the repository at this point in the history
feat: gtk-layer-shell support
  • Loading branch information
luxluth authored Jan 4, 2025
2 parents 13088b3 + c85d13c commit b8550e8
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 22 deletions.
18 changes: 17 additions & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
# Building

## Prerequisites

- [Rust](https://www.rust-lang.org/tools/install)
- [gtk4](https://www.gtk.org/docs/installations/)
- [gtk4-layer-shell](https://github.com/wmww/gtk4-layer-shell) (for gtk-layer-shell support)

## compiling

Normal build :

```sh
cargo build --release
```

Use the following if you want gtk-layer-shell support :

```sh
cargo build
cargo build --release --features=gtk-layer-shell
```

## Warning

If you encounter issues with gtk4 being "missing" despite installing it, you may need to install the `libgtk-4-dev` package.
If that still doesn't work, you need to find the gtk4.pc file with:

```sh
sudo find / -name gtk4.pc 2>/dev/null
```

Then set the PKG_CONFIG_PATH environment variable to the directory containing the gtk4.pc file:

```sh
export PKG_CONFIG_PATH=/path/to/gtk4.pc
```

Then try to compile again.
66 changes: 64 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = ["luxluth <delphin.blehoussi93@gmail.com>"]

[dependencies]
exmex = "0.20.3"
gtk = { version = "0.9.4", package = "gtk4", features = ["v4_14"] }
gtk = { version = "0.9.5", package = "gtk4", features = ["v4_14"] }
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
dbus = "0.9.7"
Expand All @@ -24,11 +24,16 @@ fragile = "2.0.0"
ini-roundtrip = "0.2.0"
rust-i18n = "3.1.2"
once_cell = "1.20.2"
gtk4-layer-shell = { version = "0.4.0", optional = true }

[[bin]]
name = "seekr"
path = "src/main.rs"

[features]
default = []
gtk-layer-shell = ["gtk4-layer-shell"]

[profile.release]
lto = true
codegen-units = 1
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ _System search util for linux_
cargo install seekr-util
```

> [!TIP]
> To enable gtk-layer-shell support, enable the `gtk-layer-shell` feature as follow
>
> ```sh
> cargo install seekr-util --features=gtk-layer-shell
> ```
>
> Make sure to have [gtk4-layer-shell](https://github.com/wmww/gtk4-layer-shell)
> installed on your system
## Configuration
On the first run of the app, configurations files will be generated into
Expand Down
86 changes: 73 additions & 13 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ pub struct GeneralConf {
pub search_placeholder: String,
}

#[derive(Clone, Debug)]
pub struct LayerShellConf {
pub active: bool,
pub top: i32,
pub left: i32,
}

impl Default for LayerShellConf {
fn default() -> Self {
Self {
active: false,
top: 50,
left: -1,
}
}
}

impl Default for GeneralConf {
fn default() -> Self {
GeneralConf {
Expand All @@ -64,17 +81,29 @@ pub struct Config {
pub css: String,
pub macros: MacroMap,
pub config_dir: PathBuf,
#[allow(dead_code)]
pub gtk_layer_shell_conf: LayerShellConf,
#[allow(dead_code)]
pub is_wayland: bool,
}

#[derive(PartialEq, Eq)]
enum ParsingState {
General,
Macros,
GtkLayerShell,
NotSet,
}

impl Config {
pub fn get_conf(conf_path: &PathBuf) -> (GeneralConf, MacroMap) {
pub fn get_conf(conf_path: &PathBuf) -> (GeneralConf, MacroMap, LayerShellConf) {
let mut general = GeneralConf::default();
let mut macros: MacroMap = MacroMap::new();
let mut gtk_layer_shell_conf = LayerShellConf::default();
if let Ok(mut f) = std::fs::File::open(conf_path) {
let mut data = String::new();
let _ = f.read_to_string(&mut data);
let mut is_in_general = false;
let mut is_in_macros = false;
let mut state: ParsingState = ParsingState::NotSet;

for (line, item) in ini_roundtrip::Parser::new(&data).enumerate() {
match item {
Expand All @@ -84,16 +113,42 @@ impl Config {
ini_roundtrip::Item::Section {
name: "general", ..
} => {
is_in_general = true;
state = ParsingState::General;
}
ini_roundtrip::Item::Section {
name: "gtk-layer-shell",
..
} => {
state = ParsingState::GtkLayerShell;
}
ini_roundtrip::Item::Section { name: "macros", .. } => {
is_in_general = false;
is_in_macros = true;
state = ParsingState::Macros;
}
ini_roundtrip::Item::Property {
key: "active", val, ..
} => {
if state == ParsingState::GtkLayerShell && val.is_some() {
gtk_layer_shell_conf.active = val.unwrap().trim() == "true";
}
}
ini_roundtrip::Item::Property {
key: "top", val, ..
} => {
if state == ParsingState::GtkLayerShell && val.is_some() {
gtk_layer_shell_conf.top = val.unwrap().parse().unwrap_or(50);
}
}
ini_roundtrip::Item::Property {
key: "left", val, ..
} => {
if state == ParsingState::GtkLayerShell && val.is_some() {
gtk_layer_shell_conf.left = val.unwrap().parse().unwrap_or(-1);
}
}
ini_roundtrip::Item::Property {
key: "theme", val, ..
} => {
if is_in_general && val.is_some() {
if state == ParsingState::General && val.is_some() {
general.theme = val.unwrap().trim().to_string();
}
}
Expand All @@ -102,14 +157,14 @@ impl Config {
val,
..
} => {
if is_in_general && val.is_some() {
if state == ParsingState::General && val.is_some() {
general.terminal = val.unwrap().trim().to_string();
}
}
ini_roundtrip::Item::Property {
key: "args", val, ..
} => {
if is_in_general && val.is_some() {
if state == ParsingState::General && val.is_some() {
general.args = val
.unwrap()
.trim()
Expand All @@ -123,13 +178,13 @@ impl Config {
val,
..
} => {
if is_in_general && val.is_some() {
if state == ParsingState::General && val.is_some() {
general.search_placeholder = val.unwrap().to_string();
}
}

ini_roundtrip::Item::Property { key, val, .. } => {
if is_in_macros && val.is_some() {
if state == ParsingState::Macros && val.is_some() {
let macro_name = MacroName::parse(&key);
let invoke_name = macro_name.invoke_name.clone();
let r#macro = MacroDef(macro_name, val.unwrap().to_string());
Expand All @@ -140,7 +195,7 @@ impl Config {
}
}
}
return (general, macros);
return (general, macros, gtk_layer_shell_conf);
}

pub fn parse(path: std::path::PathBuf) -> Self {
Expand All @@ -158,14 +213,19 @@ impl Config {
}
}

let (general, macros) = Self::get_conf(&path);
let (general, macros, gtk_layer_shell_conf) = Self::get_conf(&path);
debug!("Loaded macros .... {:#?}", macros);

return Self {
general,
css,
macros,
config_dir,
gtk_layer_shell_conf,
is_wayland: std::env::var("XDG_SESSION_TYPE")
.unwrap_or("x11".to_string())
.to_lowercase()
== "wayland",
};
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[general]

# search placeholder text
# search_placeholder = %PLACEHOLDER%
search_placeholder = %PLACEHOLDER%

# icon theme
theme = Adwaita
Expand All @@ -13,6 +13,21 @@ terminal = kitty
# terminal launch args
args = -e

# Configuration for the layer-shell protocol
# Use the <ESC> key to close the layer
[gtk-layer-shell]
# set gtk-layer-shell as active
# Will try to fallback to default window if protocol non available
active = false

# set the top offset of the window
# A negative value will center verticaly it on the screen
top = 50

# set the left offset of the window
# A negative value will center it horizontaly on the screen
left = -1

# macros configuration
# .... <name> = <cmd>
# .... <name>|<display_name> = <cmd>
Expand Down
Loading

0 comments on commit b8550e8

Please sign in to comment.