├── .gitignore ├── .gitmodules ├── COPYING ├── Cargo.toml ├── Gir.toml ├── Makefile ├── README.md ├── build.rs ├── examples └── example.rs ├── gir-files ├── Atk-1.0.gir ├── GLib-2.0.gir ├── GModule-2.0.gir ├── GObject-2.0.gir ├── Gdk-3.0.gir ├── GdkPixbuf-2.0.gir ├── Gio-2.0.gir ├── Gtk-3.0.gir ├── GtkLayerShell-0.1.gir ├── Pango-1.0.gir ├── cairo-1.0.gir └── xlib-2.0.gir ├── gtk-layer-shell-sys ├── Cargo.toml ├── Gir.toml ├── build.rs ├── src │ └── lib.rs └── tests │ ├── abi.rs │ ├── constant.c │ ├── layout.c │ └── manual.h ├── src ├── auto │ ├── enums.rs │ ├── functions.rs │ ├── mod.rs │ └── versions.txt └── lib.rs └── tests ├── abi.rs ├── constant.c ├── layout.c └── manual.h /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | Cargo.lock 4 | /gtk-layer-shell-sys/target 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "gir"] 2 | path = gir 3 | url = https://github.com/gtk-rs/gir 4 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2019 Subgraph 4 | 5 | Permission is hereby granted, free of charge, 6 | to any person obtaining a copy of this software and 7 | associated documentation files (the "Software"), to 8 | deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, 10 | merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom 12 | the Software is furnished to do so, 13 | subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice 16 | shall be included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 22 | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gtk-layer-shell-rs" 3 | version = "0.1.0" 4 | authors = ["David McKinney "] 5 | edition = "2018" 6 | 7 | [package.metadata.system-deps.gtk_layer_shell_0] 8 | name = "gtk-layer-shell-0" 9 | version = "0.1" 10 | 11 | [dependencies] 12 | libc = "0.2" 13 | bitflags = "1.0" 14 | 15 | [dependencies.ffi] 16 | package = "gtk-layer-shell-sys" 17 | path = "./gtk-layer-shell-sys" 18 | 19 | [dependencies.gdk] 20 | git = "https://github.com/gtk-rs/gtk-rs" 21 | features = ["v3_22"] 22 | 23 | [dependencies.gtk] 24 | git = "https://github.com/gtk-rs/gtk-rs" 25 | 26 | [dependencies.gtk-sys] 27 | git = "https://github.com/gtk-rs/gtk-rs" 28 | 29 | [dependencies.gio] 30 | git = "https://github.com/gtk-rs/gtk-rs" 31 | 32 | [dependencies.glib] 33 | git = "https://github.com/gtk-rs/gtk-rs" 34 | 35 | [dependencies.glib-sys] 36 | git = "https://github.com/gtk-rs/gtk-rs" 37 | 38 | [build-dependencies] 39 | pkg-config = "0.3.7" 40 | system-deps = "2.0" 41 | 42 | [dev-dependencies] 43 | shell-words = "1.0.0" 44 | tempfile = "3" 45 | -------------------------------------------------------------------------------- /Gir.toml: -------------------------------------------------------------------------------- 1 | [options] 2 | girs_dir = "./gir-files" 3 | library = "GtkLayerShell" 4 | version = "0.1" 5 | min_cfg_version = "0.1" 6 | target_path = "." 7 | work_mode = "normal" 8 | generate_safety_asserts = true 9 | deprecate_by_min_version = true 10 | single_version_file = true 11 | 12 | external_libraries = [ 13 | "Gdk", 14 | "Gtk", 15 | ] 16 | 17 | generate = [ 18 | "GtkLayerShell.Layer", 19 | "GtkLayerShell.Edge" 20 | ] 21 | 22 | manual = [ 23 | "Gtk.Window", 24 | "Gdk.Monitor" 25 | ] 26 | 27 | [[object]] 28 | name = "GtkLayerShell.*" 29 | status = "generate" 30 | [[object.function]] 31 | name = "auto_exclusive_zone_enable" 32 | [[object.function.parameter]] 33 | name = "window" 34 | [[object.function]] 35 | name = "init_for_window" 36 | [[object.function.parameter]] 37 | name = "window" 38 | [[object.function]] 39 | name = "set_anchor" 40 | [[object.function.parameter]] 41 | name = "window" 42 | [[object.function.parameter]] 43 | name = "edge" 44 | [[object.function.parameter]] 45 | name = "anchor_to_edge" 46 | [[object.function]] 47 | name = "set_exclusive_zone" 48 | [[object.function.parameter]] 49 | name = "window" 50 | [[object.function.parameter]] 51 | name = "exclusive_zone" 52 | [[object.function]] 53 | name = "set_keyboard_interactivity" 54 | [[object.function]] 55 | name = "set_layer" 56 | [[object.function.parameter]] 57 | name = "window" 58 | [[object.function.parameter]] 59 | name = "layer" 60 | [[object.function]] 61 | name = "set_margin" 62 | [[object.function.parameter]] 63 | name = "window" 64 | [[object.function.parameter]] 65 | name = "edge" 66 | [[object.function.parameter]] 67 | name = "margin_size" 68 | [[object.function]] 69 | name = "set_monitor" 70 | [[object.function.parameter]] 71 | name = "window" 72 | [[object.function.parameter]] 73 | name = "monitor" 74 | [[object.function]] 75 | name = "set_namespace" 76 | [[object.function.parameter]] 77 | name = "window" 78 | [[object.function.parameter]] 79 | name = "name_space" 80 | 81 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | GIR = gir/target/bin/gir 2 | GIR_SRC != find gir/src -name '*.rs' 3 | GIR_SRC += gir/Cargo.toml gir/Cargo.lock gir/build.rs 4 | GIR_FILES = gir-files/GtkLayerShell-0.1.gir 5 | 6 | gir: src/auto/mod.rs 7 | # Fixup enum imports for global functions since gir doesn't do it correctly 8 | sed -i 's/^use Edge/use crate::auto::enums::Edge/' src/auto/functions.rs 9 | sed -i 's/^use Layer/use crate::auto::enums::Layer/' src/auto/functions.rs 10 | cargo fmt 11 | 12 | src/auto/mod.rs : Gir.toml $(GIR) $(GIR_FILES) 13 | $(GIR) -c Gir.toml 14 | 15 | $(GIR) : $(GIR_SRC) 16 | rm -f gir/target/bin/gir 17 | cargo install --path gir --root gir/target 18 | rm -f gir/target/.crates.toml 19 | 20 | $(GIR_SRC) $(GIR_FILES) : 21 | git submodule update --init 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rust bindings for gtk-layer-shell 2 | 3 | This repository provides Rust bindings for the https://github.com/wmww/gtk-layer-shell 4 | library. To use these bindings, it is assumed that you have built and installed 5 | `gtk-layer-shell` and its dependencies. 6 | 7 | Note: there are other bindings out there that may be more actively maintained. This 8 | version is mostly for internal use. It is updated once and awhile as needed but 9 | other versions may work better for you. 10 | 11 | ## Usage 12 | 13 | Examples can be found in the `examples/` directory. To run an example: 14 | 15 | ```bash 16 | $ cargo run --example example 17 | ``` 18 | 19 | ## Regenerating bindings 20 | 21 | Sometimes the `.gir` file for gtk-layer-shell will need to be updated with 22 | new versions, API changes, etc. The bindings will need to be regenerated when 23 | the new file is added. 24 | 25 | To regenerate the bindings: 26 | 27 | ```bash 28 | $ make gir 29 | ``` 30 | 31 | Afterwards, ensure that building and running the examples still works. 32 | 33 | ## Greetz 34 | 35 | @wmww for `gtk-layer-shell` in the first place 36 | 37 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | #[cfg(not(feature = "dox"))] 6 | use std::process; 7 | 8 | #[cfg(feature = "dox")] 9 | fn main() {} // prevent linking libraries to avoid documentation failure 10 | 11 | #[cfg(not(feature = "dox"))] 12 | fn main() { 13 | if let Err(s) = system_deps::Config::new().probe() { 14 | println!("cargo:warning={}", s); 15 | process::exit(1); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/example.rs: -------------------------------------------------------------------------------- 1 | extern crate gio; 2 | extern crate gtk; 3 | extern crate gtk_layer_shell_rs as gtk_layer_shell; 4 | 5 | use gio::prelude::*; 6 | use gtk::prelude::*; 7 | 8 | use std::env::args; 9 | 10 | // This is analogous to: 11 | // https://github.com/wmww/gtk-layer-shell/blob/master/example/example.c 12 | fn activate(application: >k::Application) { 13 | // Create a normal GTK window however you like 14 | let window = gtk::ApplicationWindow::new(application); 15 | window.connect_delete_event(|_, _| { 16 | gtk::main_quit(); 17 | Inhibit(false) 18 | }); 19 | 20 | // Before the window is first realized, set it up to be a layer surface 21 | gtk_layer_shell::init_for_window(&window); 22 | 23 | // Order below normal windows 24 | gtk_layer_shell::set_layer(&window, gtk_layer_shell::Layer::Bottom); 25 | 26 | // Push other windows out of the way 27 | gtk_layer_shell::auto_exclusive_zone_enable(&window); 28 | 29 | // The margins are the gaps around the window's edges 30 | // Margins and anchors can be set like this... 31 | gtk_layer_shell::set_margin(&window, gtk_layer_shell::Edge::Left, 40); 32 | gtk_layer_shell::set_margin(&window, gtk_layer_shell::Edge::Right, 40); 33 | gtk_layer_shell::set_margin(&window, gtk_layer_shell::Edge::Top, 20); 34 | // ... or like this 35 | // Anchors are if the window is pinned to each edge of the output 36 | gtk_layer_shell::set_anchor(&window, gtk_layer_shell::Edge::Left, true); 37 | gtk_layer_shell::set_anchor(&window, gtk_layer_shell::Edge::Right, true); 38 | gtk_layer_shell::set_anchor(&window, gtk_layer_shell::Edge::Top, false); 39 | gtk_layer_shell::set_anchor(&window, gtk_layer_shell::Edge::Bottom, true); 40 | 41 | // Set up a widget 42 | let label = gtk::Label::new(Some("")); 43 | label.set_markup("GTK Layer Shell example!"); 44 | window.add(&label); 45 | window.set_border_width(12); 46 | window.show_all() 47 | } 48 | 49 | fn main() { 50 | let application = 51 | gtk::Application::new(Some("com.subgraph.gtk-layer-example"), Default::default()) 52 | .expect("Initialization failed..."); 53 | 54 | application.connect_activate(|app| { 55 | activate(app); 56 | }); 57 | 58 | application.run(&args().collect::>()); 59 | } 60 | -------------------------------------------------------------------------------- /gir-files/GModule-2.0.gir: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | The #GModule struct is an opaque data structure to represent a 12 | [dynamically-loaded module][glib-Dynamic-Loading-of-Modules]. 13 | It should only be accessed via the following functions. 14 | 15 | 16 | Closes a module. 17 | 18 | 19 | %TRUE on success 20 | 21 | 22 | 23 | 24 | a #GModule to close 25 | 26 | 27 | 28 | 29 | 30 | Ensures that a module will never be unloaded. 31 | Any future g_module_close() calls on the module will be ignored. 32 | 33 | 34 | 35 | 36 | 37 | 38 | a #GModule to make permanently resident 39 | 40 | 41 | 42 | 43 | 44 | Returns the filename that the module was opened with. 45 | 46 | If @module refers to the application itself, "main" is returned. 47 | 48 | 49 | the filename of the module 50 | 51 | 52 | 53 | 54 | a #GModule 55 | 56 | 57 | 58 | 59 | 60 | Gets a symbol pointer from a module, such as one exported 61 | by #G_MODULE_EXPORT. Note that a valid symbol can be %NULL. 62 | 63 | 64 | %TRUE on success 65 | 66 | 67 | 68 | 69 | a #GModule 70 | 71 | 72 | 73 | the name of the symbol to find 74 | 75 | 76 | 77 | returns the pointer to the symbol value 78 | 79 | 80 | 81 | 82 | 83 | A portable way to build the filename of a module. The platform-specific 84 | prefix and suffix are added to the filename, if needed, and the result 85 | is added to the directory, using the correct separator character. 86 | 87 | The directory should specify the directory where the module can be found. 88 | It can be %NULL or an empty string to indicate that the module is in a 89 | standard platform-specific directory, though this is not recommended 90 | since the wrong module may be found. 91 | 92 | For example, calling g_module_build_path() on a Linux system with a 93 | @directory of `/lib` and a @module_name of "mylibrary" will return 94 | `/lib/libmylibrary.so`. On a Windows system, using `\Windows` as the 95 | directory it will return `\Windows\mylibrary.dll`. 96 | 97 | 98 | the complete path of the module, including the standard library 99 | prefix and suffix. This should be freed when no longer needed 100 | 101 | 102 | 103 | 104 | the directory where the module is. This can be 105 | %NULL or the empty string to indicate that the standard platform-specific 106 | directories will be used, though that is not recommended 107 | 108 | 109 | 110 | the name of the module 111 | 112 | 113 | 114 | 115 | 116 | Gets a string describing the last module error. 117 | 118 | 119 | a string describing the last module error 120 | 121 | 122 | 123 | 124 | Opens a module. If the module has already been opened, 125 | its reference count is incremented. 126 | 127 | First of all g_module_open() tries to open @file_name as a module. 128 | If that fails and @file_name has the ".la"-suffix (and is a libtool 129 | archive) it tries to open the corresponding module. If that fails 130 | and it doesn't have the proper module suffix for the platform 131 | (#G_MODULE_SUFFIX), this suffix will be appended and the corresponding 132 | module will be opended. If that fails and @file_name doesn't have the 133 | ".la"-suffix, this suffix is appended and g_module_open() tries to open 134 | the corresponding module. If eventually that fails as well, %NULL is 135 | returned. 136 | 137 | 138 | a #GModule on success, or %NULL on failure 139 | 140 | 141 | 142 | 143 | the name of the file containing the module, or %NULL 144 | to obtain a #GModule representing the main program itself 145 | 146 | 147 | 148 | the flags used for opening the module. This can be the 149 | logical OR of any of the #GModuleFlags 150 | 151 | 152 | 153 | 154 | 155 | Checks if modules are supported on the current platform. 156 | 157 | 158 | %TRUE if modules are supported 159 | 160 | 161 | 162 | 163 | 164 | Specifies the type of the module initialization function. 165 | If a module contains a function named g_module_check_init() it is called 166 | automatically when the module is loaded. It is passed the #GModule structure 167 | and should return %NULL on success or a string describing the initialization 168 | error. 169 | 170 | 171 | %NULL on success, or a string describing the initialization error 172 | 173 | 174 | 175 | 176 | the #GModule corresponding to the module which has just been loaded 177 | 178 | 179 | 180 | 181 | 182 | Flags passed to g_module_open(). 183 | Note that these flags are not supported on all platforms. 184 | 185 | 186 | specifies that symbols are only resolved when 187 | needed. The default action is to bind all symbols when the module 188 | is loaded. 189 | 190 | 191 | specifies that symbols in the module should 192 | not be added to the global name space. The default action on most 193 | platforms is to place symbols in the module in the global name space, 194 | which may cause conflicts with existing symbols. 195 | 196 | 197 | mask for all flags. 198 | 199 | 200 | 201 | Specifies the type of the module function called when it is unloaded. 202 | If a module contains a function named g_module_unload() it is called 203 | automatically when the module is unloaded. 204 | It is passed the #GModule structure. 205 | 206 | 207 | 208 | 209 | 210 | 211 | the #GModule about to be unloaded 212 | 213 | 214 | 215 | 216 | 217 | A portable way to build the filename of a module. The platform-specific 218 | prefix and suffix are added to the filename, if needed, and the result 219 | is added to the directory, using the correct separator character. 220 | 221 | The directory should specify the directory where the module can be found. 222 | It can be %NULL or an empty string to indicate that the module is in a 223 | standard platform-specific directory, though this is not recommended 224 | since the wrong module may be found. 225 | 226 | For example, calling g_module_build_path() on a Linux system with a 227 | @directory of `/lib` and a @module_name of "mylibrary" will return 228 | `/lib/libmylibrary.so`. On a Windows system, using `\Windows` as the 229 | directory it will return `\Windows\mylibrary.dll`. 230 | 231 | 232 | the complete path of the module, including the standard library 233 | prefix and suffix. This should be freed when no longer needed 234 | 235 | 236 | 237 | 238 | the directory where the module is. This can be 239 | %NULL or the empty string to indicate that the standard platform-specific 240 | directories will be used, though that is not recommended 241 | 242 | 243 | 244 | the name of the module 245 | 246 | 247 | 248 | 249 | 250 | Gets a string describing the last module error. 251 | 252 | 253 | a string describing the last module error 254 | 255 | 256 | 257 | 258 | Checks if modules are supported on the current platform. 259 | 260 | 261 | %TRUE if modules are supported 262 | 263 | 264 | 265 | 266 | 267 | -------------------------------------------------------------------------------- /gir-files/GtkLayerShell-0.1.gir: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 31 | 32 | 33 | 34 | 37 | 38 | 41 | 42 | 43 | 44 | 47 | 48 | 51 | 52 | 53 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /gir-files/cairo-1.0.gir: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 14 | 17 | 20 | 21 | 24 | 27 | 30 | 33 | 36 | 39 | 42 | 45 | 48 | 51 | 54 | 57 | 60 | 63 | 66 | 69 | 72 | 75 | 78 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 105 | 108 | 111 | 114 | 117 | 120 | 123 | 126 | 129 | 132 | 135 | 138 | 141 | 144 | 147 | 148 | 151 | 154 | 157 | 160 | 161 | 164 | 167 | 170 | 173 | 176 | 179 | 182 | 185 | 188 | 191 | 194 | 197 | 200 | 203 | 206 | 209 | 212 | 215 | 218 | 221 | 224 | 227 | 230 | 233 | 236 | 239 | 242 | 245 | 248 | 251 | 252 | 255 | 258 | 261 | 264 | 267 | 270 | 273 | 276 | 277 | 280 | 283 | 286 | 287 | 290 | 293 | 296 | 299 | 300 | 303 | 306 | 309 | 312 | 313 | 316 | 319 | 320 | 323 | 326 | 329 | 332 | 333 | 336 | 339 | 342 | 343 | 346 | 349 | 352 | 355 | 358 | 361 | 362 | 365 | 368 | 371 | 374 | 377 | 380 | 381 | 384 | 387 | 390 | 393 | 394 | 397 | 400 | 403 | 406 | 409 | 412 | 415 | 416 | 419 | 422 | 425 | 428 | 431 | 432 | 435 | 438 | 441 | 444 | 447 | 450 | 453 | 456 | 459 | 462 | 463 | 466 | 469 | 472 | 475 | 478 | 481 | 484 | 487 | 490 | 493 | 496 | 499 | 502 | 505 | 508 | 511 | 514 | 517 | 520 | 523 | 526 | 529 | 532 | 535 | 538 | 541 | 542 | 545 | 548 | 551 | 554 | 557 | 560 | 563 | 566 | 567 | 570 | 573 | 576 | 579 | 582 | 585 | 588 | 589 | 592 | 595 | 598 | 601 | 604 | 605 | 608 | 611 | 614 | 617 | 620 | 623 | 626 | 627 | 630 | 633 | 636 | 639 | 640 | 643 | 646 | 647 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | -------------------------------------------------------------------------------- /gir-files/xlib-2.0.gir: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /gtk-layer-shell-sys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gtk-layer-shell-sys" 3 | version = "0.0.1" 4 | links = "gtk_layer_shell" 5 | build = "build.rs" 6 | [package.metadata.system-deps.gtk_layer_shell_0] 7 | name = "gtk-layer-shell-0" 8 | version = "0.1" 9 | [package.metadata.docs.rs] 10 | features = ["dox"] 11 | 12 | [lib] 13 | name = "gtk_layer_shell_sys" 14 | 15 | [dependencies] 16 | libc = "0.2" 17 | 18 | [dependencies.cairo-sys-rs] 19 | git = "https://github.com/gtk-rs/gtk-rs" 20 | 21 | [dependencies.gdk-sys] 22 | git = "https://github.com/gtk-rs/gtk-rs" 23 | 24 | [dependencies.gdk-pixbuf-sys] 25 | git = "https://github.com/gtk-rs/gtk-rs" 26 | 27 | [dependencies.gio-sys] 28 | git = "https://github.com/gtk-rs/gtk-rs" 29 | 30 | [dependencies.glib-sys] 31 | git = "https://github.com/gtk-rs/gtk-rs" 32 | 33 | [dependencies.gobject-sys] 34 | git = "https://github.com/gtk-rs/gtk-rs" 35 | 36 | [dependencies.gtk-sys] 37 | git = "https://github.com/gtk-rs/gtk-rs" 38 | 39 | [build-dependencies] 40 | pkg-config = "0.3.7" 41 | system-deps = "2.0" 42 | 43 | [dev-dependencies] 44 | shell-words = "1.0.0" 45 | tempfile = "3" 46 | 47 | [features] 48 | dox = [] 49 | -------------------------------------------------------------------------------- /gtk-layer-shell-sys/Gir.toml: -------------------------------------------------------------------------------- 1 | [options] 2 | library = "GtkLayerShell" 3 | version = "0.1" 4 | target_path = "." 5 | min_cfg_version = "0.1" 6 | work_mode = "sys" 7 | girs_dir = "../gir-files" 8 | 9 | external_libraries = [ 10 | "Cairo", 11 | "Gdk", 12 | "GdkPixbuf", 13 | "Gio", 14 | "GLib", 15 | "GObject", 16 | "Gtk", 17 | ] 18 | -------------------------------------------------------------------------------- /gtk-layer-shell-sys/build.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir @ 00040a2) 2 | // from gir-files (https://github.com/gtk-rs/gir-files @ c47bea4) 3 | // DO NOT EDIT 4 | 5 | #[cfg(not(feature = "dox"))] 6 | use std::process; 7 | 8 | #[cfg(feature = "dox")] 9 | fn main() {} // prevent linking libraries to avoid documentation failure 10 | 11 | #[cfg(not(feature = "dox"))] 12 | fn main() { 13 | if let Err(s) = system_deps::Config::new().probe() { 14 | println!("cargo:warning={}", s); 15 | process::exit(1); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gtk-layer-shell-sys/src/lib.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir @ 00040a2) 2 | // from gir-files (https://github.com/gtk-rs/gir-files @ c47bea4) 3 | // DO NOT EDIT 4 | 5 | #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] 6 | #![allow(clippy::approx_constant, clippy::type_complexity, clippy::unreadable_literal)] 7 | #![cfg_attr(feature = "dox", feature(doc_cfg))] 8 | 9 | extern crate libc; 10 | extern crate cairo_sys as cairo; 11 | extern crate gdk_sys as gdk; 12 | extern crate gdk_pixbuf_sys as gdk_pixbuf; 13 | extern crate gio_sys as gio; 14 | extern crate glib_sys as glib; 15 | extern crate gobject_sys as gobject; 16 | extern crate gtk_sys as gtk; 17 | 18 | #[allow(unused_imports)] 19 | use libc::{c_int, c_char, c_uchar, c_float, c_uint, c_double, 20 | c_short, c_ushort, c_long, c_ulong, 21 | c_void, size_t, ssize_t, intptr_t, uintptr_t, time_t, FILE}; 22 | 23 | #[allow(unused_imports)] 24 | use glib::{gboolean, gconstpointer, gpointer, GType}; 25 | 26 | // Enums 27 | pub type GtkLayerShellEdge = c_int; 28 | pub const GTK_LAYER_SHELL_EDGE_LEFT: GtkLayerShellEdge = 0; 29 | pub const GTK_LAYER_SHELL_EDGE_RIGHT: GtkLayerShellEdge = 1; 30 | pub const GTK_LAYER_SHELL_EDGE_TOP: GtkLayerShellEdge = 2; 31 | pub const GTK_LAYER_SHELL_EDGE_BOTTOM: GtkLayerShellEdge = 3; 32 | pub const GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER: GtkLayerShellEdge = 4; 33 | 34 | pub type GtkLayerShellLayer = c_int; 35 | pub const GTK_LAYER_SHELL_LAYER_BACKGROUND: GtkLayerShellLayer = 0; 36 | pub const GTK_LAYER_SHELL_LAYER_BOTTOM: GtkLayerShellLayer = 1; 37 | pub const GTK_LAYER_SHELL_LAYER_TOP: GtkLayerShellLayer = 2; 38 | pub const GTK_LAYER_SHELL_LAYER_OVERLAY: GtkLayerShellLayer = 3; 39 | pub const GTK_LAYER_SHELL_LAYER_ENTRY_NUMBER: GtkLayerShellLayer = 4; 40 | 41 | #[link(name = "gtk-layer-shell")] 42 | extern "C" { 43 | 44 | //========================================================================= 45 | // Other functions 46 | //========================================================================= 47 | pub fn gtk_layer_auto_exclusive_zone_enable(window: *mut gtk::GtkWindow); 48 | pub fn gtk_layer_init_for_window(window: *mut gtk::GtkWindow); 49 | pub fn gtk_layer_set_anchor(window: *mut gtk::GtkWindow, edge: GtkLayerShellEdge, anchor_to_edge: gboolean); 50 | pub fn gtk_layer_set_exclusive_zone(window: *mut gtk::GtkWindow, exclusive_zone: c_int); 51 | pub fn gtk_layer_set_keyboard_interactivity(window: *mut gtk::GtkWindow, interacitvity: gboolean); 52 | pub fn gtk_layer_set_layer(window: *mut gtk::GtkWindow, layer: GtkLayerShellLayer); 53 | pub fn gtk_layer_set_margin(window: *mut gtk::GtkWindow, edge: GtkLayerShellEdge, margin_size: c_int); 54 | pub fn gtk_layer_set_monitor(window: *mut gtk::GtkWindow, monitor: *mut gdk::GdkMonitor); 55 | pub fn gtk_layer_set_namespace(window: *mut gtk::GtkWindow, name_space: *const c_char); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /gtk-layer-shell-sys/tests/abi.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir @ 00040a2) 2 | // from gir-files (https://github.com/gtk-rs/gir-files @ c47bea4) 3 | // DO NOT EDIT 4 | 5 | extern crate gtk_layer_shell_sys; 6 | extern crate tempfile; 7 | 8 | use std::env; 9 | use std::error::Error; 10 | use std::path::Path; 11 | use std::mem::{align_of, size_of}; 12 | use std::process::Command; 13 | use std::str; 14 | use tempfile::Builder; 15 | use gtk_layer_shell_sys::*; 16 | 17 | static PACKAGES: &[&str] = &["gtk-layer-shell-0"]; 18 | 19 | #[derive(Clone, Debug)] 20 | struct Compiler { 21 | pub args: Vec, 22 | } 23 | 24 | impl Compiler { 25 | pub fn new() -> Result> { 26 | let mut args = get_var("CC", "cc")?; 27 | args.push("-Wno-deprecated-declarations".to_owned()); 28 | // For %z support in printf when using MinGW. 29 | args.push("-D__USE_MINGW_ANSI_STDIO".to_owned()); 30 | args.extend(get_var("CFLAGS", "")?); 31 | args.extend(get_var("CPPFLAGS", "")?); 32 | args.extend(pkg_config_cflags(PACKAGES)?); 33 | Ok(Compiler { args }) 34 | } 35 | 36 | pub fn define<'a, V: Into>>(&mut self, var: &str, val: V) { 37 | let arg = match val.into() { 38 | None => format!("-D{}", var), 39 | Some(val) => format!("-D{}={}", var, val), 40 | }; 41 | self.args.push(arg); 42 | } 43 | 44 | pub fn compile(&self, src: &Path, out: &Path) -> Result<(), Box> { 45 | let mut cmd = self.to_command(); 46 | cmd.arg(src); 47 | cmd.arg("-o"); 48 | cmd.arg(out); 49 | let status = cmd.spawn()?.wait()?; 50 | if !status.success() { 51 | return Err(format!("compilation command {:?} failed, {}", 52 | &cmd, status).into()); 53 | } 54 | Ok(()) 55 | } 56 | 57 | fn to_command(&self) -> Command { 58 | let mut cmd = Command::new(&self.args[0]); 59 | cmd.args(&self.args[1..]); 60 | cmd 61 | } 62 | } 63 | 64 | fn get_var(name: &str, default: &str) -> Result, Box> { 65 | match env::var(name) { 66 | Ok(value) => Ok(shell_words::split(&value)?), 67 | Err(env::VarError::NotPresent) => Ok(shell_words::split(default)?), 68 | Err(err) => Err(format!("{} {}", name, err).into()), 69 | } 70 | } 71 | 72 | fn pkg_config_cflags(packages: &[&str]) -> Result, Box> { 73 | if packages.is_empty() { 74 | return Ok(Vec::new()); 75 | } 76 | let mut cmd = Command::new("pkg-config"); 77 | cmd.arg("--cflags"); 78 | cmd.args(packages); 79 | let out = cmd.output()?; 80 | if !out.status.success() { 81 | return Err(format!("command {:?} returned {}", 82 | &cmd, out.status).into()); 83 | } 84 | let stdout = str::from_utf8(&out.stdout)?; 85 | Ok(shell_words::split(stdout.trim())?) 86 | } 87 | 88 | 89 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] 90 | struct Layout { 91 | size: usize, 92 | alignment: usize, 93 | } 94 | 95 | #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] 96 | struct Results { 97 | /// Number of successfully completed tests. 98 | passed: usize, 99 | /// Total number of failed tests (including those that failed to compile). 100 | failed: usize, 101 | /// Number of tests that failed to compile. 102 | failed_to_compile: usize, 103 | } 104 | 105 | impl Results { 106 | fn record_passed(&mut self) { 107 | self.passed += 1; 108 | } 109 | fn record_failed(&mut self) { 110 | self.failed += 1; 111 | } 112 | fn record_failed_to_compile(&mut self) { 113 | self.failed += 1; 114 | self.failed_to_compile += 1; 115 | } 116 | fn summary(&self) -> String { 117 | format!( 118 | "{} passed; {} failed (compilation errors: {})", 119 | self.passed, 120 | self.failed, 121 | self.failed_to_compile) 122 | } 123 | fn expect_total_success(&self) { 124 | if self.failed == 0 { 125 | println!("OK: {}", self.summary()); 126 | } else { 127 | panic!("FAILED: {}", self.summary()); 128 | }; 129 | } 130 | } 131 | 132 | #[test] 133 | fn cross_validate_constants_with_c() { 134 | let tmpdir = Builder::new().prefix("abi").tempdir().expect("temporary directory"); 135 | let cc = Compiler::new().expect("configured compiler"); 136 | 137 | assert_eq!("1", 138 | get_c_value(tmpdir.path(), &cc, "1").expect("C constant"), 139 | "failed to obtain correct constant value for 1"); 140 | 141 | let mut results : Results = Default::default(); 142 | for (i, &(name, rust_value)) in RUST_CONSTANTS.iter().enumerate() { 143 | match get_c_value(tmpdir.path(), &cc, name) { 144 | Err(e) => { 145 | results.record_failed_to_compile(); 146 | eprintln!("{}", e); 147 | }, 148 | Ok(ref c_value) => { 149 | if rust_value == c_value { 150 | results.record_passed(); 151 | } else { 152 | results.record_failed(); 153 | eprintln!("Constant value mismatch for {}\nRust: {:?}\nC: {:?}", 154 | name, rust_value, c_value); 155 | } 156 | } 157 | }; 158 | if (i + 1) % 25 == 0 { 159 | println!("constants ... {}", results.summary()); 160 | } 161 | } 162 | results.expect_total_success(); 163 | } 164 | 165 | #[test] 166 | fn cross_validate_layout_with_c() { 167 | let tmpdir = Builder::new().prefix("abi").tempdir().expect("temporary directory"); 168 | let cc = Compiler::new().expect("configured compiler"); 169 | 170 | assert_eq!(Layout {size: 1, alignment: 1}, 171 | get_c_layout(tmpdir.path(), &cc, "char").expect("C layout"), 172 | "failed to obtain correct layout for char type"); 173 | 174 | let mut results : Results = Default::default(); 175 | for (i, &(name, rust_layout)) in RUST_LAYOUTS.iter().enumerate() { 176 | match get_c_layout(tmpdir.path(), &cc, name) { 177 | Err(e) => { 178 | results.record_failed_to_compile(); 179 | eprintln!("{}", e); 180 | }, 181 | Ok(c_layout) => { 182 | if rust_layout == c_layout { 183 | results.record_passed(); 184 | } else { 185 | results.record_failed(); 186 | eprintln!("Layout mismatch for {}\nRust: {:?}\nC: {:?}", 187 | name, rust_layout, &c_layout); 188 | } 189 | } 190 | }; 191 | if (i + 1) % 25 == 0 { 192 | println!("layout ... {}", results.summary()); 193 | } 194 | } 195 | results.expect_total_success(); 196 | } 197 | 198 | fn get_c_layout(dir: &Path, cc: &Compiler, name: &str) -> Result> { 199 | let exe = dir.join("layout"); 200 | let mut cc = cc.clone(); 201 | cc.define("ABI_TYPE_NAME", name); 202 | cc.compile(Path::new("tests/layout.c"), &exe)?; 203 | 204 | let mut abi_cmd = Command::new(exe); 205 | let output = abi_cmd.output()?; 206 | if !output.status.success() { 207 | return Err(format!("command {:?} failed, {:?}", 208 | &abi_cmd, &output).into()); 209 | } 210 | 211 | let stdout = str::from_utf8(&output.stdout)?; 212 | let mut words = stdout.trim().split_whitespace(); 213 | let size = words.next().unwrap().parse().unwrap(); 214 | let alignment = words.next().unwrap().parse().unwrap(); 215 | Ok(Layout {size, alignment}) 216 | } 217 | 218 | fn get_c_value(dir: &Path, cc: &Compiler, name: &str) -> Result> { 219 | let exe = dir.join("constant"); 220 | let mut cc = cc.clone(); 221 | cc.define("ABI_CONSTANT_NAME", name); 222 | cc.compile(Path::new("tests/constant.c"), &exe)?; 223 | 224 | let mut abi_cmd = Command::new(exe); 225 | let output = abi_cmd.output()?; 226 | if !output.status.success() { 227 | return Err(format!("command {:?} failed, {:?}", 228 | &abi_cmd, &output).into()); 229 | } 230 | 231 | let output = str::from_utf8(&output.stdout)?.trim(); 232 | if !output.starts_with("###gir test###") || 233 | !output.ends_with("###gir test###") { 234 | return Err(format!("command {:?} return invalid output, {:?}", 235 | &abi_cmd, &output).into()); 236 | } 237 | 238 | Ok(String::from(&output[14..(output.len() - 14)])) 239 | } 240 | 241 | const RUST_LAYOUTS: &[(&str, Layout)] = &[ 242 | ("GtkLayerShellEdge", Layout {size: size_of::(), alignment: align_of::()}), 243 | ("GtkLayerShellLayer", Layout {size: size_of::(), alignment: align_of::()}), 244 | ]; 245 | 246 | const RUST_CONSTANTS: &[(&str, &str)] = &[ 247 | ("(gint) GTK_LAYER_SHELL_EDGE_BOTTOM", "3"), 248 | ("(gint) GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER", "4"), 249 | ("(gint) GTK_LAYER_SHELL_EDGE_LEFT", "0"), 250 | ("(gint) GTK_LAYER_SHELL_EDGE_RIGHT", "1"), 251 | ("(gint) GTK_LAYER_SHELL_EDGE_TOP", "2"), 252 | ("(gint) GTK_LAYER_SHELL_LAYER_BACKGROUND", "0"), 253 | ("(gint) GTK_LAYER_SHELL_LAYER_BOTTOM", "1"), 254 | ("(gint) GTK_LAYER_SHELL_LAYER_ENTRY_NUMBER", "4"), 255 | ("(gint) GTK_LAYER_SHELL_LAYER_OVERLAY", "3"), 256 | ("(gint) GTK_LAYER_SHELL_LAYER_TOP", "2"), 257 | ]; 258 | 259 | 260 | -------------------------------------------------------------------------------- /gtk-layer-shell-sys/tests/constant.c: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir @ 00040a2) 2 | // from gir-files (https://github.com/gtk-rs/gir-files @ c47bea4) 3 | // DO NOT EDIT 4 | 5 | #include "manual.h" 6 | #include 7 | 8 | int main() { 9 | printf(_Generic((ABI_CONSTANT_NAME), 10 | char *: "###gir test###%s###gir test###\n", 11 | const char *: "###gir test###%s###gir test###\n", 12 | char: "###gir test###%c###gir test###\n", 13 | signed char: "###gir test###%hhd###gir test###\n", 14 | unsigned char: "###gir test###%hhu###gir test###\n", 15 | short int: "###gir test###%hd###gir test###\n", 16 | unsigned short int: "###gir test###%hu###gir test###\n", 17 | int: "###gir test###%d###gir test###\n", 18 | unsigned int: "###gir test###%u###gir test###\n", 19 | long: "###gir test###%ld###gir test###\n", 20 | unsigned long: "###gir test###%lu###gir test###\n", 21 | long long: "###gir test###%lld###gir test###\n", 22 | unsigned long long: "###gir test###%llu###gir test###\n", 23 | double: "###gir test###%f###gir test###\n", 24 | long double: "###gir test###%ld###gir test###\n"), 25 | ABI_CONSTANT_NAME); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /gtk-layer-shell-sys/tests/layout.c: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir @ 00040a2) 2 | // from gir-files (https://github.com/gtk-rs/gir-files @ c47bea4) 3 | // DO NOT EDIT 4 | 5 | #include "manual.h" 6 | #include 7 | #include 8 | 9 | int main() { 10 | printf("%zu\n%zu", sizeof(ABI_TYPE_NAME), alignof(ABI_TYPE_NAME)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /gtk-layer-shell-sys/tests/manual.h: -------------------------------------------------------------------------------- 1 | // Feel free to edit this file, it won't be regenerated by gir generator unless removed. 2 | 3 | #include 4 | -------------------------------------------------------------------------------- /src/auto/enums.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use glib::translate::*; 6 | use std::fmt; 7 | 8 | #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] 9 | #[non_exhaustive] 10 | #[doc(alias = "GtkLayerShellEdge")] 11 | pub enum Edge { 12 | #[doc(alias = "GTK_LAYER_SHELL_EDGE_LEFT")] 13 | Left, 14 | #[doc(alias = "GTK_LAYER_SHELL_EDGE_RIGHT")] 15 | Right, 16 | #[doc(alias = "GTK_LAYER_SHELL_EDGE_TOP")] 17 | Top, 18 | #[doc(alias = "GTK_LAYER_SHELL_EDGE_BOTTOM")] 19 | Bottom, 20 | #[doc(alias = "GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER")] 21 | EntryNumber, 22 | #[doc(hidden)] 23 | __Unknown(i32), 24 | } 25 | 26 | impl fmt::Display for Edge { 27 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 28 | write!( 29 | f, 30 | "Edge::{}", 31 | match *self { 32 | Edge::Left => "Left", 33 | Edge::Right => "Right", 34 | Edge::Top => "Top", 35 | Edge::Bottom => "Bottom", 36 | Edge::EntryNumber => "EntryNumber", 37 | _ => "Unknown", 38 | } 39 | ) 40 | } 41 | } 42 | 43 | #[doc(hidden)] 44 | impl ToGlib for Edge { 45 | type GlibType = ffi::GtkLayerShellEdge; 46 | 47 | fn to_glib(&self) -> ffi::GtkLayerShellEdge { 48 | match *self { 49 | Edge::Left => ffi::GTK_LAYER_SHELL_EDGE_LEFT, 50 | Edge::Right => ffi::GTK_LAYER_SHELL_EDGE_RIGHT, 51 | Edge::Top => ffi::GTK_LAYER_SHELL_EDGE_TOP, 52 | Edge::Bottom => ffi::GTK_LAYER_SHELL_EDGE_BOTTOM, 53 | Edge::EntryNumber => ffi::GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER, 54 | Edge::__Unknown(value) => value, 55 | } 56 | } 57 | } 58 | 59 | #[doc(hidden)] 60 | impl FromGlib for Edge { 61 | unsafe fn from_glib(value: ffi::GtkLayerShellEdge) -> Self { 62 | skip_assert_initialized!(); 63 | match value { 64 | 0 => Edge::Left, 65 | 1 => Edge::Right, 66 | 2 => Edge::Top, 67 | 3 => Edge::Bottom, 68 | 4 => Edge::EntryNumber, 69 | value => Edge::__Unknown(value), 70 | } 71 | } 72 | } 73 | 74 | #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] 75 | #[non_exhaustive] 76 | #[doc(alias = "GtkLayerShellLayer")] 77 | pub enum Layer { 78 | #[doc(alias = "GTK_LAYER_SHELL_LAYER_BACKGROUND")] 79 | Background, 80 | #[doc(alias = "GTK_LAYER_SHELL_LAYER_BOTTOM")] 81 | Bottom, 82 | #[doc(alias = "GTK_LAYER_SHELL_LAYER_TOP")] 83 | Top, 84 | #[doc(alias = "GTK_LAYER_SHELL_LAYER_OVERLAY")] 85 | Overlay, 86 | #[doc(alias = "GTK_LAYER_SHELL_LAYER_ENTRY_NUMBER")] 87 | EntryNumber, 88 | #[doc(hidden)] 89 | __Unknown(i32), 90 | } 91 | 92 | impl fmt::Display for Layer { 93 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 94 | write!( 95 | f, 96 | "Layer::{}", 97 | match *self { 98 | Layer::Background => "Background", 99 | Layer::Bottom => "Bottom", 100 | Layer::Top => "Top", 101 | Layer::Overlay => "Overlay", 102 | Layer::EntryNumber => "EntryNumber", 103 | _ => "Unknown", 104 | } 105 | ) 106 | } 107 | } 108 | 109 | #[doc(hidden)] 110 | impl ToGlib for Layer { 111 | type GlibType = ffi::GtkLayerShellLayer; 112 | 113 | fn to_glib(&self) -> ffi::GtkLayerShellLayer { 114 | match *self { 115 | Layer::Background => ffi::GTK_LAYER_SHELL_LAYER_BACKGROUND, 116 | Layer::Bottom => ffi::GTK_LAYER_SHELL_LAYER_BOTTOM, 117 | Layer::Top => ffi::GTK_LAYER_SHELL_LAYER_TOP, 118 | Layer::Overlay => ffi::GTK_LAYER_SHELL_LAYER_OVERLAY, 119 | Layer::EntryNumber => ffi::GTK_LAYER_SHELL_LAYER_ENTRY_NUMBER, 120 | Layer::__Unknown(value) => value, 121 | } 122 | } 123 | } 124 | 125 | #[doc(hidden)] 126 | impl FromGlib for Layer { 127 | unsafe fn from_glib(value: ffi::GtkLayerShellLayer) -> Self { 128 | skip_assert_initialized!(); 129 | match value { 130 | 0 => Layer::Background, 131 | 1 => Layer::Bottom, 132 | 2 => Layer::Top, 133 | 3 => Layer::Overlay, 134 | 4 => Layer::EntryNumber, 135 | value => Layer::__Unknown(value), 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/auto/functions.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use crate::Edge; 6 | use crate::Layer; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | 10 | #[doc(alias = "gtk_layer_auto_exclusive_zone_enable")] 11 | pub fn auto_exclusive_zone_enable>(window: &P) { 12 | assert_initialized_main_thread!(); 13 | unsafe { 14 | ffi::gtk_layer_auto_exclusive_zone_enable(window.as_ref().to_glib_none().0); 15 | } 16 | } 17 | 18 | #[doc(alias = "gtk_layer_init_for_window")] 19 | pub fn init_for_window>(window: &P) { 20 | assert_initialized_main_thread!(); 21 | unsafe { 22 | ffi::gtk_layer_init_for_window(window.as_ref().to_glib_none().0); 23 | } 24 | } 25 | 26 | #[doc(alias = "gtk_layer_set_anchor")] 27 | pub fn set_anchor>(window: &P, edge: Edge, anchor_to_edge: bool) { 28 | assert_initialized_main_thread!(); 29 | unsafe { 30 | ffi::gtk_layer_set_anchor( 31 | window.as_ref().to_glib_none().0, 32 | edge.to_glib(), 33 | anchor_to_edge.to_glib(), 34 | ); 35 | } 36 | } 37 | 38 | #[doc(alias = "gtk_layer_set_exclusive_zone")] 39 | pub fn set_exclusive_zone>(window: &P, exclusive_zone: i32) { 40 | assert_initialized_main_thread!(); 41 | unsafe { 42 | ffi::gtk_layer_set_exclusive_zone(window.as_ref().to_glib_none().0, exclusive_zone); 43 | } 44 | } 45 | 46 | #[doc(alias = "gtk_layer_set_keyboard_interactivity")] 47 | pub fn set_keyboard_interactivity>(window: &P, interacitvity: bool) { 48 | assert_initialized_main_thread!(); 49 | unsafe { 50 | ffi::gtk_layer_set_keyboard_interactivity( 51 | window.as_ref().to_glib_none().0, 52 | interacitvity.to_glib(), 53 | ); 54 | } 55 | } 56 | 57 | #[doc(alias = "gtk_layer_set_layer")] 58 | pub fn set_layer>(window: &P, layer: Layer) { 59 | assert_initialized_main_thread!(); 60 | unsafe { 61 | ffi::gtk_layer_set_layer(window.as_ref().to_glib_none().0, layer.to_glib()); 62 | } 63 | } 64 | 65 | #[doc(alias = "gtk_layer_set_margin")] 66 | pub fn set_margin>(window: &P, edge: Edge, margin_size: i32) { 67 | assert_initialized_main_thread!(); 68 | unsafe { 69 | ffi::gtk_layer_set_margin( 70 | window.as_ref().to_glib_none().0, 71 | edge.to_glib(), 72 | margin_size, 73 | ); 74 | } 75 | } 76 | 77 | #[doc(alias = "gtk_layer_set_monitor")] 78 | pub fn set_monitor>(window: &P, monitor: &gdk::Monitor) { 79 | assert_initialized_main_thread!(); 80 | unsafe { 81 | ffi::gtk_layer_set_monitor(window.as_ref().to_glib_none().0, monitor.to_glib_none().0); 82 | } 83 | } 84 | 85 | #[doc(alias = "gtk_layer_set_namespace")] 86 | pub fn set_namespace>(window: &P, name_space: &str) { 87 | assert_initialized_main_thread!(); 88 | unsafe { 89 | ffi::gtk_layer_set_namespace( 90 | window.as_ref().to_glib_none().0, 91 | name_space.to_glib_none().0, 92 | ); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/auto/mod.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | mod enums; 6 | pub use self::enums::Edge; 7 | pub use self::enums::Layer; 8 | 9 | pub mod functions; 10 | 11 | #[doc(hidden)] 12 | pub mod traits {} 13 | -------------------------------------------------------------------------------- /src/auto/versions.txt: -------------------------------------------------------------------------------- 1 | Generated by gir (https://github.com/gtk-rs/gir @ 00040a2) 2 | from gir-files (https://github.com/gtk-rs/gir-files @ 03e0995) 3 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate bitflags; 2 | extern crate libc; 3 | 4 | extern crate gdk; 5 | extern crate glib; 6 | extern crate glib_sys; 7 | extern crate gtk; 8 | 9 | macro_rules! assert_initialized_main_thread { 10 | () => { 11 | if !::gtk::is_initialized_main_thread() { 12 | if ::gtk::is_initialized() { 13 | panic!("GTK may only be used from the main thread."); 14 | } else { 15 | panic!("GTK has not been initialized. Call `gtk::init` first."); 16 | } 17 | } 18 | }; 19 | } 20 | 21 | macro_rules! skip_assert_initialized { 22 | () => {}; 23 | } 24 | 25 | mod auto; 26 | pub use auto::functions::*; 27 | pub use auto::*; 28 | -------------------------------------------------------------------------------- /tests/abi.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | extern crate tempfile; 6 | 7 | use ffi::*; 8 | use gtk_layer_shell_rs::*; 9 | use std::env; 10 | use std::error::Error; 11 | use std::mem::{align_of, size_of}; 12 | use std::path::Path; 13 | use std::process::Command; 14 | use std::str; 15 | use tempfile::Builder; 16 | 17 | static PACKAGES: &[&str] = &["gtk-layer-shell-0"]; 18 | 19 | #[derive(Clone, Debug)] 20 | struct Compiler { 21 | pub args: Vec, 22 | } 23 | 24 | impl Compiler { 25 | pub fn new() -> Result> { 26 | let mut args = get_var("CC", "cc")?; 27 | args.push("-Wno-deprecated-declarations".to_owned()); 28 | // For %z support in printf when using MinGW. 29 | args.push("-D__USE_MINGW_ANSI_STDIO".to_owned()); 30 | args.extend(get_var("CFLAGS", "")?); 31 | args.extend(get_var("CPPFLAGS", "")?); 32 | args.extend(pkg_config_cflags(PACKAGES)?); 33 | Ok(Compiler { args }) 34 | } 35 | 36 | pub fn define<'a, V: Into>>(&mut self, var: &str, val: V) { 37 | let arg = match val.into() { 38 | None => format!("-D{}", var), 39 | Some(val) => format!("-D{}={}", var, val), 40 | }; 41 | self.args.push(arg); 42 | } 43 | 44 | pub fn compile(&self, src: &Path, out: &Path) -> Result<(), Box> { 45 | let mut cmd = self.to_command(); 46 | cmd.arg(src); 47 | cmd.arg("-o"); 48 | cmd.arg(out); 49 | let status = cmd.spawn()?.wait()?; 50 | if !status.success() { 51 | return Err(format!("compilation command {:?} failed, {}", &cmd, status).into()); 52 | } 53 | Ok(()) 54 | } 55 | 56 | fn to_command(&self) -> Command { 57 | let mut cmd = Command::new(&self.args[0]); 58 | cmd.args(&self.args[1..]); 59 | cmd 60 | } 61 | } 62 | 63 | fn get_var(name: &str, default: &str) -> Result, Box> { 64 | match env::var(name) { 65 | Ok(value) => Ok(shell_words::split(&value)?), 66 | Err(env::VarError::NotPresent) => Ok(shell_words::split(default)?), 67 | Err(err) => Err(format!("{} {}", name, err).into()), 68 | } 69 | } 70 | 71 | fn pkg_config_cflags(packages: &[&str]) -> Result, Box> { 72 | if packages.is_empty() { 73 | return Ok(Vec::new()); 74 | } 75 | let mut cmd = Command::new("pkg-config"); 76 | cmd.arg("--cflags"); 77 | cmd.args(packages); 78 | let out = cmd.output()?; 79 | if !out.status.success() { 80 | return Err(format!("command {:?} returned {}", &cmd, out.status).into()); 81 | } 82 | let stdout = str::from_utf8(&out.stdout)?; 83 | Ok(shell_words::split(stdout.trim())?) 84 | } 85 | 86 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] 87 | struct Layout { 88 | size: usize, 89 | alignment: usize, 90 | } 91 | 92 | #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] 93 | struct Results { 94 | /// Number of successfully completed tests. 95 | passed: usize, 96 | /// Total number of failed tests (including those that failed to compile). 97 | failed: usize, 98 | /// Number of tests that failed to compile. 99 | failed_to_compile: usize, 100 | } 101 | 102 | impl Results { 103 | fn record_passed(&mut self) { 104 | self.passed += 1; 105 | } 106 | fn record_failed(&mut self) { 107 | self.failed += 1; 108 | } 109 | fn record_failed_to_compile(&mut self) { 110 | self.failed += 1; 111 | self.failed_to_compile += 1; 112 | } 113 | fn summary(&self) -> String { 114 | format!( 115 | "{} passed; {} failed (compilation errors: {})", 116 | self.passed, self.failed, self.failed_to_compile 117 | ) 118 | } 119 | fn expect_total_success(&self) { 120 | if self.failed == 0 { 121 | println!("OK: {}", self.summary()); 122 | } else { 123 | panic!("FAILED: {}", self.summary()); 124 | }; 125 | } 126 | } 127 | 128 | #[test] 129 | fn cross_validate_constants_with_c() { 130 | let tmpdir = Builder::new() 131 | .prefix("abi") 132 | .tempdir() 133 | .expect("temporary directory"); 134 | let cc = Compiler::new().expect("configured compiler"); 135 | 136 | assert_eq!( 137 | "1", 138 | get_c_value(tmpdir.path(), &cc, "1").expect("C constant"), 139 | "failed to obtain correct constant value for 1" 140 | ); 141 | 142 | let mut results: Results = Default::default(); 143 | for (i, &(name, rust_value)) in RUST_CONSTANTS.iter().enumerate() { 144 | match get_c_value(tmpdir.path(), &cc, name) { 145 | Err(e) => { 146 | results.record_failed_to_compile(); 147 | eprintln!("{}", e); 148 | } 149 | Ok(ref c_value) => { 150 | if rust_value == c_value { 151 | results.record_passed(); 152 | } else { 153 | results.record_failed(); 154 | eprintln!( 155 | "Constant value mismatch for {}\nRust: {:?}\nC: {:?}", 156 | name, rust_value, c_value 157 | ); 158 | } 159 | } 160 | }; 161 | if (i + 1) % 25 == 0 { 162 | println!("constants ... {}", results.summary()); 163 | } 164 | } 165 | results.expect_total_success(); 166 | } 167 | 168 | #[test] 169 | fn cross_validate_layout_with_c() { 170 | let tmpdir = Builder::new() 171 | .prefix("abi") 172 | .tempdir() 173 | .expect("temporary directory"); 174 | let cc = Compiler::new().expect("configured compiler"); 175 | 176 | assert_eq!( 177 | Layout { 178 | size: 1, 179 | alignment: 1 180 | }, 181 | get_c_layout(tmpdir.path(), &cc, "char").expect("C layout"), 182 | "failed to obtain correct layout for char type" 183 | ); 184 | 185 | let mut results: Results = Default::default(); 186 | for (i, &(name, rust_layout)) in RUST_LAYOUTS.iter().enumerate() { 187 | match get_c_layout(tmpdir.path(), &cc, name) { 188 | Err(e) => { 189 | results.record_failed_to_compile(); 190 | eprintln!("{}", e); 191 | } 192 | Ok(c_layout) => { 193 | if rust_layout == c_layout { 194 | results.record_passed(); 195 | } else { 196 | results.record_failed(); 197 | eprintln!( 198 | "Layout mismatch for {}\nRust: {:?}\nC: {:?}", 199 | name, rust_layout, &c_layout 200 | ); 201 | } 202 | } 203 | }; 204 | if (i + 1) % 25 == 0 { 205 | println!("layout ... {}", results.summary()); 206 | } 207 | } 208 | results.expect_total_success(); 209 | } 210 | 211 | fn get_c_layout(dir: &Path, cc: &Compiler, name: &str) -> Result> { 212 | let exe = dir.join("layout"); 213 | let mut cc = cc.clone(); 214 | cc.define("ABI_TYPE_NAME", name); 215 | cc.compile(Path::new("tests/layout.c"), &exe)?; 216 | 217 | let mut abi_cmd = Command::new(exe); 218 | let output = abi_cmd.output()?; 219 | if !output.status.success() { 220 | return Err(format!("command {:?} failed, {:?}", &abi_cmd, &output).into()); 221 | } 222 | 223 | let stdout = str::from_utf8(&output.stdout)?; 224 | let mut words = stdout.trim().split_whitespace(); 225 | let size = words.next().unwrap().parse().unwrap(); 226 | let alignment = words.next().unwrap().parse().unwrap(); 227 | Ok(Layout { size, alignment }) 228 | } 229 | 230 | fn get_c_value(dir: &Path, cc: &Compiler, name: &str) -> Result> { 231 | let exe = dir.join("constant"); 232 | let mut cc = cc.clone(); 233 | cc.define("ABI_CONSTANT_NAME", name); 234 | cc.compile(Path::new("tests/constant.c"), &exe)?; 235 | 236 | let mut abi_cmd = Command::new(exe); 237 | let output = abi_cmd.output()?; 238 | if !output.status.success() { 239 | return Err(format!("command {:?} failed, {:?}", &abi_cmd, &output).into()); 240 | } 241 | 242 | let output = str::from_utf8(&output.stdout)?.trim(); 243 | if !output.starts_with("###gir test###") || !output.ends_with("###gir test###") { 244 | return Err(format!( 245 | "command {:?} return invalid output, {:?}", 246 | &abi_cmd, &output 247 | ) 248 | .into()); 249 | } 250 | 251 | Ok(String::from(&output[14..(output.len() - 14)])) 252 | } 253 | 254 | const RUST_LAYOUTS: &[(&str, Layout)] = &[ 255 | ( 256 | "GtkLayerShellEdge", 257 | Layout { 258 | size: size_of::(), 259 | alignment: align_of::(), 260 | }, 261 | ), 262 | ( 263 | "GtkLayerShellLayer", 264 | Layout { 265 | size: size_of::(), 266 | alignment: align_of::(), 267 | }, 268 | ), 269 | ]; 270 | 271 | const RUST_CONSTANTS: &[(&str, &str)] = &[ 272 | ("(gint) GTK_LAYER_SHELL_EDGE_BOTTOM", "3"), 273 | ("(gint) GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER", "4"), 274 | ("(gint) GTK_LAYER_SHELL_EDGE_LEFT", "0"), 275 | ("(gint) GTK_LAYER_SHELL_EDGE_RIGHT", "1"), 276 | ("(gint) GTK_LAYER_SHELL_EDGE_TOP", "2"), 277 | ("(gint) GTK_LAYER_SHELL_LAYER_BACKGROUND", "0"), 278 | ("(gint) GTK_LAYER_SHELL_LAYER_BOTTOM", "1"), 279 | ("(gint) GTK_LAYER_SHELL_LAYER_ENTRY_NUMBER", "4"), 280 | ("(gint) GTK_LAYER_SHELL_LAYER_OVERLAY", "3"), 281 | ("(gint) GTK_LAYER_SHELL_LAYER_TOP", "2"), 282 | ]; 283 | -------------------------------------------------------------------------------- /tests/constant.c: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | #include "manual.h" 6 | #include 7 | 8 | int main() { 9 | printf(_Generic((ABI_CONSTANT_NAME), 10 | char *: "###gir test###%s###gir test###\n", 11 | const char *: "###gir test###%s###gir test###\n", 12 | char: "###gir test###%c###gir test###\n", 13 | signed char: "###gir test###%hhd###gir test###\n", 14 | unsigned char: "###gir test###%hhu###gir test###\n", 15 | short int: "###gir test###%hd###gir test###\n", 16 | unsigned short int: "###gir test###%hu###gir test###\n", 17 | int: "###gir test###%d###gir test###\n", 18 | unsigned int: "###gir test###%u###gir test###\n", 19 | long: "###gir test###%ld###gir test###\n", 20 | unsigned long: "###gir test###%lu###gir test###\n", 21 | long long: "###gir test###%lld###gir test###\n", 22 | unsigned long long: "###gir test###%llu###gir test###\n", 23 | double: "###gir test###%f###gir test###\n", 24 | long double: "###gir test###%ld###gir test###\n"), 25 | ABI_CONSTANT_NAME); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /tests/layout.c: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | #include "manual.h" 6 | #include 7 | #include 8 | 9 | int main() { 10 | printf("%zu\n%zu", sizeof(ABI_TYPE_NAME), alignof(ABI_TYPE_NAME)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/manual.h: -------------------------------------------------------------------------------- 1 | // Feel free to edit this file, it won't be regenerated by gir generator unless removed. 2 | 3 | #include 4 | --------------------------------------------------------------------------------