From cc989c67dbf2b60eddff9403cca8d7f20c184852 Mon Sep 17 00:00:00 2001 From: Leopold Luley Date: Mon, 30 Sep 2024 17:52:46 +0200 Subject: [PATCH] Remember window size and maximized state. --- Cargo.lock | 415 +++++++++++++++++++++- gnome/Cargo.toml | 5 + gnome/src/config/imp.rs | 67 ++++ gnome/src/config/mod.rs | 19 + gnome/src/main.rs | 7 +- gnome/src/search_window/imp.rs | 24 +- gnome/src/search_window/search_window.blp | 2 - 7 files changed, 521 insertions(+), 18 deletions(-) create mode 100644 gnome/src/config/imp.rs create mode 100644 gnome/src/config/mod.rs diff --git a/Cargo.lock b/Cargo.lock index d1b537e..6d75299 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,6 +35,16 @@ dependencies = [ "memchr 2.7.4", ] +[[package]] +name = "atomicwrites" +version = "0.4.2" +source = "git+https://github.com/jackpot51/rust-atomicwrites#043ab4859d53ffd3d55334685303d8df39c9f768" +dependencies = [ + "rustix", + "tempfile", + "windows-sys 0.48.0", +] + [[package]] name = "autocfg" version = "1.3.0" @@ -56,11 +66,26 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +dependencies = [ + "serde", +] [[package]] name = "block" @@ -91,7 +116,7 @@ version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8a0ea147c94108c9613235388f540e4d14c327f7081c9e471fc8ee8a2533e69" dependencies = [ - "bitflags", + "bitflags 2.6.0", "cairo-sys-rs", "glib", "libc", @@ -157,6 +182,7 @@ name = "clapgrep-gnome" version = "1.0.0" dependencies = [ "clapgrep-core", + "cosmic-config", "flume", "gettext-rs", "gtk-blueprint", @@ -164,6 +190,22 @@ dependencies = [ "libadwaita", ] +[[package]] +name = "cosmic-config" +version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic.git?rev=228eb4d70d581be88bacb1e261106a58603d847b#228eb4d70d581be88bacb1e261106a58603d847b" +dependencies = [ + "atomicwrites", + "dirs", + "known-folders", + "notify", + "once_cell", + "ron", + "serde", + "tracing", + "xdg", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -173,6 +215,15 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" version = "0.8.5" @@ -207,6 +258,27 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dotext" version = "0.1.1" @@ -250,6 +322,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "error-chain" version = "0.10.0" @@ -268,6 +350,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + [[package]] name = "field-offset" version = "0.3.6" @@ -278,6 +366,18 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "filetime" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "libredox", + "windows-sys 0.59.0", +] + [[package]] name = "flate2" version = "1.0.31" @@ -300,6 +400,15 @@ dependencies = [ "spin", ] +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -501,7 +610,7 @@ version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b19429cb83fcbf1f00b31ae3a123fab5cd3761bdd15b0cc07905804742f0d0e4" dependencies = [ - "bitflags", + "bitflags 2.6.0", "futures-channel", "futures-core", "futures-executor", @@ -802,6 +911,26 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + [[package]] name = "itoa" version = "1.0.11" @@ -817,6 +946,35 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "known-folders" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7d9a1740cc8b46e259a0eb787d79d855e79ff10b9855a5eba58868d5da7927c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -860,12 +1018,29 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.6.0", + "libc", + "redox_syscall", +] + [[package]] name = "linked-hash-map" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "locale_config" version = "0.3.0" @@ -975,6 +1150,18 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.48.0", +] + [[package]] name = "msdos_time" version = "0.1.6" @@ -1004,6 +1191,25 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.6.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "walkdir", + "windows-sys 0.48.0", +] + [[package]] name = "num-conv" version = "0.1.0" @@ -1073,6 +1279,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "pango" version = "0.20.1" @@ -1236,6 +1448,26 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags 2.6.0", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + [[package]] name = "regex" version = "1.10.6" @@ -1265,6 +1497,18 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "ron" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" +dependencies = [ + "base64", + "bitflags 2.6.0", + "serde", + "serde_derive", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1280,6 +1524,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "ryu" version = "1.0.18" @@ -1425,6 +1682,19 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f227968ec00f0e5322f9b8173c7a0cbcff6181a0a5b28e9892491c286277231" +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if 1.0.0", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "termcolor" version = "1.4.1" @@ -1434,6 +1704,26 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.74", +] + [[package]] name = "time" version = "0.1.45" @@ -1536,6 +1826,37 @@ dependencies = [ "winnow 0.6.18", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.74", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + [[package]] name = "type1-encoding-parser" version = "0.1.0" @@ -1680,13 +2001,22 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1695,7 +2025,22 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -1704,28 +2049,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1738,24 +2101,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -1780,6 +2167,12 @@ dependencies = [ "memchr 2.7.4", ] +[[package]] +name = "xdg" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546" + [[package]] name = "zip" version = "0.2.8" diff --git a/gnome/Cargo.toml b/gnome/Cargo.toml index 5c96a39..0891f46 100644 --- a/gnome/Cargo.toml +++ b/gnome/Cargo.toml @@ -10,3 +10,8 @@ gtk = { version = "0.9.0", package = "gtk4", features = ["blueprint", "v4_14"] } flume = "0.11.0" gettext-rs = { version = "0.7.1", features = ["gettext-system"] } gtk-blueprint = "0.2.0" + +[dependencies.cosmic-config] +git = "https://github.com/pop-os/libcosmic.git" +rev = "228eb4d70d581be88bacb1e261106a58603d847b" +default-features = false diff --git a/gnome/src/config/imp.rs b/gnome/src/config/imp.rs new file mode 100644 index 0000000..8431d80 --- /dev/null +++ b/gnome/src/config/imp.rs @@ -0,0 +1,67 @@ +use cosmic_config::{ConfigGet, ConfigSet}; +use glib::prelude::*; +use gtk::{glib, subclass::prelude::*}; +use std::cell::{Cell, OnceCell}; + +use crate::APP_ID; + +#[derive(Default, glib::Properties)] +#[properties(wrapper_type = super::Config)] +pub struct Config { + #[property(get, set = Self::set_window_width, default = 1600)] + window_width: Cell, + #[property(get, set = Self::set_window_height, default = 900)] + window_height: Cell, + #[property(get, set = Self::set_window_maximized, default = false)] + window_maximized: Cell, + + config: OnceCell, +} + +impl Config { + fn set_window_width(&self, width: i32) { + let config = self.config.get().unwrap(); + let _ = config.set("window_width", width); + self.window_width.set(width); + } + + fn set_window_height(&self, height: i32) { + let config = self.config.get().unwrap(); + let _ = config.set("window_height", height); + self.window_height.set(height); + } + + fn set_window_maximized(&self, maximized: bool) { + let config = self.config.get().unwrap(); + let _ = config.set("window_maximized", maximized); + self.window_maximized.set(maximized); + } +} + +// Basic declaration of our type for the GObject type system +#[glib::object_subclass] +impl ObjectSubclass for Config { + const NAME: &'static str = "ClapgrepConfig"; + type Type = super::Config; +} + +#[glib::derived_properties] +impl ObjectImpl for Config { + fn constructed(&self) { + let config = cosmic_config::Config::new(APP_ID, 1).expect("failed to open config"); + + if let Ok(window_width) = config.get("window_width") { + self.window_width.set(window_width); + } + + if let Ok(window_height) = config.get("window_height") { + self.window_height.set(window_height); + } + + if let Ok(window_maximized) = config.get("window_maximized") { + self.window_maximized.set(window_maximized); + } + + let _ = self.config.set(config); + } +} diff --git a/gnome/src/config/mod.rs b/gnome/src/config/mod.rs new file mode 100644 index 0000000..d0c4b4e --- /dev/null +++ b/gnome/src/config/mod.rs @@ -0,0 +1,19 @@ +mod imp; + +use gtk::glib; + +glib::wrapper! { + pub struct Config(ObjectSubclass); +} + +impl Config { + pub fn new() -> Config { + glib::Object::new() + } +} + +impl Default for Config { + fn default() -> Self { + Self::new() + } +} diff --git a/gnome/src/main.rs b/gnome/src/main.rs index e4a4058..5c9cec6 100644 --- a/gnome/src/main.rs +++ b/gnome/src/main.rs @@ -5,14 +5,17 @@ use gtk::{gio::SimpleAction, License}; use gtk_blueprint::include_blp; use std::path::PathBuf; +mod config; mod error_window; mod search_match; mod search_model; mod search_result; mod search_window; +const APP_ID: &str = "de.leopoldluley.Clapgrep"; + fn setup_gettext() { - let mut text_domain = gettextrs::TextDomain::new("de.leopoldluley.Clapgrep"); + let mut text_domain = gettextrs::TextDomain::new(APP_ID); if cfg!(debug_assertions) { let assets_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) @@ -30,7 +33,7 @@ fn main() { setup_gettext(); let app = adw::Application::builder() - .application_id("de.leopoldluley.Clapgrep") + .application_id(APP_ID) .flags(ApplicationFlags::HANDLES_OPEN) .build(); diff --git a/gnome/src/search_window/imp.rs b/gnome/src/search_window/imp.rs index ceb6055..cbdbfa5 100644 --- a/gnome/src/search_window/imp.rs +++ b/gnome/src/search_window/imp.rs @@ -1,3 +1,4 @@ +use crate::{config::Config, error_window::ErrorWindow, search_model::SearchModel}; use adw::subclass::prelude::*; use clapgrep_core::{ extended::ExtendedType, @@ -17,8 +18,6 @@ use std::{ path::{Path, PathBuf}, }; -use crate::{error_window::ErrorWindow, search_model::SearchModel}; - #[derive(CompositeTemplate, glib::Properties, Default)] #[template(file = "src/search_window/search_window.blp")] #[properties(wrapper_type = super::SearchWindow)] @@ -61,6 +60,7 @@ pub struct SearchWindow { pub has_errors: Cell, pub manager: RefCell>, + pub config: Config, } #[glib::object_subclass] @@ -222,8 +222,26 @@ impl SearchWindow { impl ObjectImpl for SearchWindow { fn constructed(&self) { self.parent_constructed(); - let obj = self.obj(); + + self.config + .bind_property("window_width", obj.as_ref(), "default_width") + .bidirectional() + .sync_create() + .build(); + + self.config + .bind_property("window_height", obj.as_ref(), "default_height") + .bidirectional() + .sync_create() + .build(); + + self.config + .bind_property("window_maximized", obj.as_ref(), "maximized") + .bidirectional() + .sync_create() + .build(); + obj.results().connect_items_changed(clone!( #[weak] obj, diff --git a/gnome/src/search_window/search_window.blp b/gnome/src/search_window/search_window.blp index bf0c5a0..031fe8d 100644 --- a/gnome/src/search_window/search_window.blp +++ b/gnome/src/search_window/search_window.blp @@ -2,8 +2,6 @@ using Gtk 4.0; using Adw 1; template $ClapgrepSearchWindow: Adw.ApplicationWindow { - default-width: 1600; - default-height: 900; title: _("Clapgrep"); content: Adw.NavigationSplitView {