diff --git a/CHANGELOG.md b/CHANGELOG.md index e9702f7ff3..2ddcc7a46b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ You can find its changes [documented below](#070---2021-01-01). - X11: detect keyboard layout ([#1779] by [@Maan2003]) - WindowDesc::with_config ([#1929] by [@Maan2003]) - `Notification::route` ([#1978] by [@xarvic]) +- Build on OpenBSD ([#1993] by [@klemensn]) ### Changed @@ -522,6 +523,7 @@ Last release without a changelog :( [@DrGabble]: https://github.com/DrGabble [@lisael]: https://github.com/lisael [@jenra-uwu]: https://github.com/jenra-uwu +[@klemensn]: https://github.com/klemensn [#599]: https://github.com/linebender/druid/pull/599 [#611]: https://github.com/linebender/druid/pull/611 @@ -798,6 +800,7 @@ Last release without a changelog :( [#1953]: https://github.com/linebender/druid/pull/1953 [#1967]: https://github.com/linebender/druid/pull/1967 [#1978]: https://github.com/linebender/druid/pull/1978 +[#1993]: https://github.com/linebender/druid/pull/1993 [#1996]: https://github.com/linebender/druid/pull/1996 [Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master diff --git a/README.md b/README.md index d2e4a537c8..033d6ad498 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,12 @@ druid = { git = "https://github.com/linebender/druid.git" } On Linux, Druid requires gtk+3; see [GTK installation page]. (On ubuntu-based distro, running `sudo apt-get install libgtk-3-dev` from the terminal will do the job.) +#### OpenBSD + +On OpenBSD, Druid requires gtk+3; install from packages: +```sh +pkg_add gtk+3 +``` Alternatively, there is an X11 backend available, although it is currently [missing quite a few features](https://github.com/linebender/druid/issues?q=is%3Aopen+is%3Aissue+label%3Ashell%2Fx11+label%3Amissing). @@ -152,7 +158,7 @@ Druid relies on the [Piet library] for drawing and text layout. Piet is a 2D gra abstraction with multiple backends: `piet-direct2d`, `piet-coregraphics`, `piet-cairo`, `piet-web`, and `piet-svg` are currently available, and a GPU backend is planned. In terms of Druid platform support via Piet, macOS uses `piet-coregraphics`, -Linux uses `piet-cairo`, Windows uses `piet-direct2d`, and web uses `piet-web`. +Linux and OpenBSD use `piet-cairo`, Windows uses `piet-direct2d`, and web uses `piet-web`. ```rust use druid::kurbo::{BezPath, Point, Rect}; diff --git a/docs/src/setup.md b/docs/src/setup.md index a415f7bdae..6ae32c3cee 100644 --- a/docs/src/setup.md +++ b/docs/src/setup.md @@ -24,6 +24,12 @@ sudo dnf install gtk3-devel glib2-devel See [GTK installation page] for more installation instructions. +### OpenBSD +On OpenBSD, Druid requires gtk+3; install from packages: +```no_compile +pkg_add gtk+3 +``` + ## Starting a project Starting a project is as easy as creating an empty application with ```no_compile diff --git a/druid-shell/Cargo.toml b/druid-shell/Cargo.toml index 3e2b25cec2..66a53954f9 100755 --- a/druid-shell/Cargo.toml +++ b/druid-shell/Cargo.toml @@ -75,7 +75,7 @@ core-graphics = "0.22.0" foreign-types = "0.3.2" bitflags = "1.2.1" -[target.'cfg(target_os="linux")'.dependencies] +[target.'cfg(any(target_os="linux", target_os="openbsd"))'.dependencies] # TODO(x11/dependencies): only use feature "xcb" if using X11 cairo-rs = { version = "0.14.0", default_features = false, features = ["xcb"] } cairo-sys-rs = { version = "0.14.0", default_features = false, optional = true } diff --git a/druid-shell/build.rs b/druid-shell/build.rs index 287cfa7675..c35d720e84 100644 --- a/druid-shell/build.rs +++ b/druid-shell/build.rs @@ -7,7 +7,9 @@ fn main() { use std::env; use std::path::PathBuf; - if env::var("CARGO_CFG_TARGET_OS").unwrap() != "linux" { + if env::var("CARGO_CFG_TARGET_OS").unwrap() != "linux" + && env::var("CARGO_CFG_TARGET_OS").unwrap() != "openbsd" + { return; } diff --git a/druid-shell/src/backend/mod.rs b/druid-shell/src/backend/mod.rs index 434fe6d59f..f07150398d 100644 --- a/druid-shell/src/backend/mod.rs +++ b/druid-shell/src/backend/mod.rs @@ -28,18 +28,18 @@ pub use mac::*; #[cfg(target_os = "macos")] pub(crate) mod shared; -#[cfg(all(feature = "x11", target_os = "linux"))] +#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "openbsd")))] mod x11; -#[cfg(all(feature = "x11", target_os = "linux"))] +#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "openbsd")))] pub use x11::*; -#[cfg(all(feature = "x11", target_os = "linux"))] +#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "openbsd")))] pub(crate) mod shared; -#[cfg(all(not(feature = "x11"), target_os = "linux"))] +#[cfg(all(not(feature = "x11"), any(target_os = "linux", target_os = "openbsd")))] mod gtk; -#[cfg(all(not(feature = "x11"), target_os = "linux"))] +#[cfg(all(not(feature = "x11"), any(target_os = "linux", target_os = "openbsd")))] pub use self::gtk::*; -#[cfg(all(not(feature = "x11"), target_os = "linux"))] +#[cfg(all(not(feature = "x11"), any(target_os = "linux", target_os = "openbsd")))] pub(crate) mod shared; #[cfg(target_arch = "wasm32")] diff --git a/druid-shell/src/backend/shared/keyboard.rs b/druid-shell/src/backend/shared/keyboard.rs index 0acb9a9288..dfc9144a59 100644 --- a/druid-shell/src/backend/shared/keyboard.rs +++ b/druid-shell/src/backend/shared/keyboard.rs @@ -17,7 +17,10 @@ #[allow(unused)] use keyboard_types::{Code, Location}; -#[cfg(any(all(feature = "x11", target_os = "linux"), target_os = "macos"))] +#[cfg(any( + all(feature = "x11", any(target_os = "linux", target_os = "openbsd")), + target_os = "macos" +))] /// Map key code to location. /// /// The logic for this is adapted from InitKeyEvent in TextInputHandler (in the Mozilla @@ -51,7 +54,7 @@ pub fn code_to_location(code: Code) -> Location { } } -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "linux", target_os = "openbsd"))] /// Map hardware keycode to code. /// /// In theory, the hardware keycode is device dependent, but in diff --git a/druid-shell/src/backend/shared/mod.rs b/druid-shell/src/backend/shared/mod.rs index 68c7c83e1d..da805c19ab 100644 --- a/druid-shell/src/backend/shared/mod.rs +++ b/druid-shell/src/backend/shared/mod.rs @@ -15,7 +15,7 @@ //! Logic that is shared by more than one backend. cfg_if::cfg_if! { - if #[cfg(any(target_os = "macos", target_os = "linux"))] { + if #[cfg(any(target_os = "macos", target_os = "linux", target_os = "openbsd"))] { mod keyboard; pub use keyboard::*; } diff --git a/druid-shell/src/clipboard.rs b/druid-shell/src/clipboard.rs index ab992824c4..ef4be9908a 100644 --- a/druid-shell/src/clipboard.rs +++ b/druid-shell/src/clipboard.rs @@ -224,7 +224,7 @@ cfg_if::cfg_if! { } else { impl ClipboardFormat { cfg_if::cfg_if! { - if #[cfg(target_os = "linux")] { + if #[cfg(any(target_os = "linux", target_os = "openbsd"))] { // trial and error; this is the most supported string type for gtk? pub const TEXT: &'static str = "UTF8_STRING"; } else { diff --git a/druid-shell/src/dialog.rs b/druid-shell/src/dialog.rs index f1074dc203..0d8352b429 100644 --- a/druid-shell/src/dialog.rs +++ b/druid-shell/src/dialog.rs @@ -37,7 +37,7 @@ pub struct FileInfo { } /// Type of file dialog. -#[cfg(not(all(target_os = "linux", feature = "x11")))] +#[cfg(not(all(any(target_os = "linux", target_os = "openbsd"), feature = "x11")))] #[derive(Clone, Copy, PartialEq)] pub enum FileDialogType { /// File open dialog. diff --git a/druid-shell/src/hotkey.rs b/druid-shell/src/hotkey.rs index 25b69c3761..9ea095d7f6 100644 --- a/druid-shell/src/hotkey.rs +++ b/druid-shell/src/hotkey.rs @@ -126,13 +126,13 @@ impl HotKey { pub enum SysMods { None, Shift, - /// Command on macOS, and Ctrl on windows/linux + /// Command on macOS, and Ctrl on windows/linux/OpenBSD Cmd, - /// Command + Alt on macOS, Ctrl + Alt on windows/linux + /// Command + Alt on macOS, Ctrl + Alt on windows/linux/OpenBSD AltCmd, - /// Command + Shift on macOS, Ctrl + Shift on windows/linux + /// Command + Shift on macOS, Ctrl + Shift on windows/linux/OpenBSD CmdShift, - /// Command + Alt + Shift on macOS, Ctrl + Alt + Shift on windows/linux + /// Command + Alt + Shift on macOS, Ctrl + Alt + Shift on windows/linux/OpenBSD AltCmdShift, } diff --git a/druid-shell/src/lib.rs b/druid-shell/src/lib.rs index d80f1c782d..9ca04976ba 100644 --- a/druid-shell/src/lib.rs +++ b/druid-shell/src/lib.rs @@ -36,7 +36,7 @@ // Rename `gtk_rs` back to `gtk`. // This allows us to use `gtk` as the feature name. // The `target_os` requirement is there to exclude anything `wasm` like. -#[cfg(all(target_os = "linux", feature = "gtk"))] +#[cfg(all(any(target_os = "linux", target_os = "openbsd"), feature = "gtk"))] extern crate gtk_rs as gtk; // Reexport the version of `image` we are using. diff --git a/druid-shell/src/platform/mod.rs b/druid-shell/src/platform/mod.rs index 70b27a3de7..4e79baeb94 100644 --- a/druid-shell/src/platform/mod.rs +++ b/druid-shell/src/platform/mod.rs @@ -14,7 +14,7 @@ //! Platorm specific extensions. -#[cfg(any(doc, target_os = "linux"))] +#[cfg(any(doc, any(target_os = "linux", target_os = "openbsd")))] pub mod linux; #[cfg(any(doc, target_os = "macos"))] diff --git a/druid/examples/markdown_preview.rs b/druid/examples/markdown_preview.rs index a0ec0d680b..dcc101e12e 100644 --- a/druid/examples/markdown_preview.rs +++ b/druid/examples/markdown_preview.rs @@ -239,7 +239,7 @@ fn make_menu(_window_id: Option, _app_state: &AppState, _env: { base = base.entry(druid::platform_menus::mac::application::default()) } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "openbsd"))] { base = base.entry(druid::platform_menus::win::file::default()); } diff --git a/druid/examples/multiwin.rs b/druid/examples/multiwin.rs index 86a29471eb..051c8af624 100644 --- a/druid/examples/multiwin.rs +++ b/druid/examples/multiwin.rs @@ -199,7 +199,7 @@ fn make_menu(_: Option, state: &State, _: &Env) -> Menu { { base = druid::platform_menus::mac::menu_bar(); } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "openbsd"))] { base = base.entry(druid::platform_menus::win::file::default()); } diff --git a/druid/examples/readme.md b/druid/examples/readme.md index affdead8ab..17ede03902 100644 --- a/druid/examples/readme.md +++ b/druid/examples/readme.md @@ -3,7 +3,7 @@ There are several different kind of examples, some demonstrate one particular Druid concept, some are tools used for testing and debugging, and others are more complete examples of how to tie everything together. -The latter are listed separately under [showcases](##Showcases). +The latter are listed separately under [showcases](#Showcases). ## Anim ``` @@ -15,21 +15,21 @@ This example shows how to make a simple animation using `Event::AnimFrame`. ``` cargo run --example async_event ``` -Demonstrates receiving data from some outside source, and updating the UI in response. This is similar to [blocking function](##Blocking Function) but here the data source is fully independent, and runs for the lifetime of the program. +Demonstrates receiving data from some outside source, and updating the UI in response. This is similar to [blocking function](#Blocking Function) but here the data source is fully independent, and runs for the lifetime of the program. -## Blocking Functions +## Blocking Function ``` -cargo run --example blocking_functions +cargo run --example blocking_function ``` Sometimes you need to fetch some data from disk or from the internet, but you should never block the UI thread with long running operations! Instead you should run this task in a separate thread, and have it send -you the data as it arrives. This is very similar to [async event](##Async Event) +you the data as it arrives. This is very similar to [async event](#Async Event) except the event is initiated by the main thread. ## Cursor ``` -cargo run --example cursor +cargo run --example cursor --features="image png" ``` This example demonstrates how to set the cursor icon, and how to use a custom cursor. @@ -55,12 +55,25 @@ cargo run --example hello This shows some of the basics of druid. If you need a start of how to build an application with a text-box and some labels this is where to start. ## Hello_web +For more info and prerequistes see [druid/examples/hello_web/README.md](druid/examples/hello_web/README.md). ``` cd druid/examples/hello_web wasm-pack build --out-dir pkg --out-name hello_web ``` +[View at http://localhost:8000](http://localhost:8000]. + This is an example of how to get almost any druid application can be used on the web. This is just the hello_world example but should work for all of them. +## Web +For more info and prerequistes see [druid/examples/web/README.md](druid/examples/web/README.md). +``` +cd druid/examples/web +wasm-pack build --out-dir pkg --out-name web +``` +[View at http://localhost:8000](http://localhost:8000]. + +Simple web app. + ## Identity ``` cargo run --example identity @@ -91,6 +104,12 @@ cargo run --example list --features="im" ``` This shows you how you could, for example, add items to lists and delete them. +## Markdown Preview +``` +cargo run --example markdown_preview +``` +An example of markdown preview on the left side and editable text on the right side. + ## Multiple Windows ``` cargo run --example multiwin @@ -107,7 +126,7 @@ Opening and saving files is crucial for a lot of applications. This shows you ho ``` cargo run --example panels ``` -Very similar to [layout](##Layout) but it splits the screen into 2 segments +Very similar to [layout](#Layout) but it splits the screen into 2 segments ## Value Formatting @@ -138,18 +157,13 @@ cargo run --example split_demo An example of how to split a widget in 2 in various ways. This also includes having the user drag the border!! ## Sub Window +Not working, no sub-window seen? ``` cargo run --example sub_window ``` This shows you how to make a completely new window with shared state. -## Styled_text -``` -cargo run --example styled_text -``` -Not all text should look the same. You are able to change a lot of things, color, size, and monospace. This example shows how to change these propperties. - ## Svg ``` cargo run --example svg --features="svg" @@ -164,13 +178,25 @@ Switches are useful in many ways, this example shows how to use the druid built- ## Tabs ``` -cargo run --example tabs +cargo run --example tabs --features="im" +``` +Tabs allow you to seperate different portions of the UI. This example shows you how to use them in druid. similar to [view switcher](#View Switcher) but with with a different purpose. + +## Text +``` +cargo run --example text +``` +Text shows the effects of TextAlignment and LineBreaker types. + +## TextBox +``` +cargo run --example textbox ``` -Tabs allow you to seperate different portions of the UI. This example shows you how to use them in druid. similar to [view switcher](##View Switcher) but with with a different purpose. +Textbox demostrates some of the possible configuraitons of the TextBox widget. -## Timers +## Timer ``` -cargo run --example timers +cargo run --example timer ``` Timers allow you to send events to your widgets at a certain points inthe future. This example shows how to use them. @@ -184,7 +210,7 @@ This shows you how to make the window transparent, so the rest of the desktop sh ``` cargo run --example view_switcher ``` -Very similar to [tabs](##Tabs) but this allows you to have more control over it. This allows you to switch out widgets on the fly. +Very similar to [tabs](#Tabs) but this allows you to have more control over it. This allows you to switch out widgets on the fly. # Showcases @@ -223,7 +249,7 @@ A simple implementation of Conway's game of life. You can change the evolution s ## Image ``` -cargo run --example image +cargo run --example image --features "image png" ``` Image shows off all the knobs you can turn on images. You can play with them with real time results, which you to figure out what settings are best for you. @@ -242,11 +268,12 @@ This is a showcase is scrolling through an image gradient square. The square is cargo run --example styled_text ``` -In druid you can change all kinds of styling aspects of text. This shows off some of them. +In druid you can change all kinds of styling aspects of text as not all text should look +the same. This showcases some of those things such as, color, size, and monospace. ## Widget Gallery ``` -cargo run --example widget_gallery +cargo run --example widget_gallery --features="svg im image png" ``` This is a showcase of some simple widgets with their default styling. These are interactive, but you cannot change any of their styling. diff --git a/druid/examples/sub_window.rs b/druid/examples/sub_window.rs index 7ed1a8c6e3..d078371373 100644 --- a/druid/examples/sub_window.rs +++ b/druid/examples/sub_window.rs @@ -352,7 +352,6 @@ fn build_root_widget() -> impl Widget { WindowConfig::default() .show_titlebar(false) .window_size(Size::new(100., 100.)) - .set_position(Point::new(1000.0, 500.0)) .set_level(WindowLevel::AppWindow), col, data.clone(), diff --git a/druid/examples/textbox.rs b/druid/examples/textbox.rs index 8fbcbe603a..a1b7673436 100644 --- a/druid/examples/textbox.rs +++ b/druid/examples/textbox.rs @@ -98,7 +98,7 @@ fn make_menu(_window: Option, _data: &AppState, _env: &Env) - { base = base.entry(druid::platform_menus::mac::application::default()) } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "openbsd"))] { base = base.entry(druid::platform_menus::win::file::default()); } diff --git a/druid/src/lib.rs b/druid/src/lib.rs index 0d233b36e0..7cbc0bf900 100644 --- a/druid/src/lib.rs +++ b/druid/src/lib.rs @@ -15,7 +15,7 @@ //! Simple data-oriented GUI. //! //! Druid lets you build simple interactive graphical applications that -//! can be deployed on Windows, macOS, Linux, and the web. +//! can be deployed on Windows, macOS, Linux, OpenBSD and the web. //! //! Druid is built on top of [`druid-shell`], which implements all of the //! lower-level, platform-specific code, providing a common abstraction @@ -97,7 +97,7 @@ //! which is made available via the [`im` module]. //! * `svg` - Scalable Vector Graphics for icons and other scalable images using the [`usvg` crate]. //! * `image` - Bitmap image support using the [`image` crate]. -//! * `x11` - Work-in-progress X11 Linux backend instead of GTK. +//! * `x11` - Work-in-progress X11 for Linux and OpenBSD backend instead of GTK. //! //! Features can be added with `cargo`. For example, in your `Cargo.toml`: //! ```no_compile diff --git a/druid/src/menu/mod.rs b/druid/src/menu/mod.rs index a8ce0a2e86..514ac53aed 100644 --- a/druid/src/menu/mod.rs +++ b/druid/src/menu/mod.rs @@ -170,7 +170,7 @@ impl MenuManager { #[cfg(target_os = "macos")] return Some(MenuManager::new(|_, _, _| sys::mac::application::default())); - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "openbsd"))] return None; // we want to explicitly handle all platforms; log if a platform is missing. diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index 54a1ba2966..3c2fad75eb 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -33,7 +33,11 @@ use crate::{ use super::LabelText; const CURSOR_BLINK_DURATION: Duration = Duration::from_millis(500); -const MAC_OR_LINUX: bool = cfg!(any(target_os = "macos", target_os = "linux")); +const MAC_OR_LINUX_OR_OBSD: bool = cfg!(any( + target_os = "macos", + target_os = "linux", + target_os = "openbsd" +)); /// When we scroll after editing or movement, we show a little extra of the document. const SCROLL_TO_INSETS: Insets = Insets::uniform_xy(40.0, 0.0); @@ -513,7 +517,7 @@ impl Widget for TextBox { ctx.request_paint(); } LifeCycle::FocusChanged(false) => { - if self.text().can_write() && MAC_OR_LINUX && !self.multiline { + if self.text().can_write() && MAC_OR_LINUX_OR_OBSD && !self.multiline { let selection = self.text().borrow().selection(); let selection = Selection::new(selection.active, selection.active); let _ = self.text_mut().borrow_mut().set_selection(selection);