Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions druid-shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ default-target = "x86_64-pc-windows-msvc"

[features]
default = ["gtk"]
gtk = ["gio", "gdk", "gdk-sys", "glib", "glib-sys", "gtk-sys", "gtk-rs", "gdk-pixbuf"]
x11 = ["x11rb", "nix", "cairo-sys-rs", "bindgen", "pkg-config"]
gtk = ["gdk-sys", "glib-sys", "gtk-sys", "gtk-rs"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need -sys neither, they are re-exported as ffi.

x11 = ["x11rb", "nix", "cairo-sys-rs"]
# Implement HasRawWindowHandle for WindowHandle
raw-win-handle = ["raw-window-handle"]

Expand All @@ -41,7 +41,7 @@ serde = ["kurbo/serde"]
[dependencies]
# NOTE: When changing the piet or kurbo versions, ensure that
# the kurbo version included in piet is compatible with the kurbo version specified here.
piet-common = "=0.4.1"
piet-common = "=0.5.0-pre1"
kurbo = "0.8.1"

tracing = "0.1.22"
Expand Down Expand Up @@ -77,17 +77,13 @@ bitflags = "1.2.1"

[target.'cfg(target_os="linux")'.dependencies]
# TODO(x11/dependencies): only use feature "xcb" if using X11
cairo-rs = { version = "0.9.1", default_features = false, features = ["xcb"] }
cairo-sys-rs = { version = "0.10.0", default_features = false, optional = true }
gio = { version = "0.9.1", optional = true }
gdk = { version = "0.13.2", optional = true }
gdk-pixbuf = { version = "0.9.0", optional = true }
gdk-sys = { version = "0.10.0", optional = true }
cairo-rs = { version = "0.14.0", default_features = false, features = ["xcb"] }
cairo-sys-rs = { version = "0.14.0", default_features = false, optional = true }
gdk-sys = { version = "0.14.0", optional = true }
# `gtk` gets renamed to `gtk-rs` so that we can use `gtk` as the feature name.
gtk-rs = { version = "0.9.2", features = ["v3_22"], package = "gtk", optional = true }
glib = { version = "0.10.1", optional = true }
glib-sys = { version = "0.10.0", optional = true }
gtk-sys = { version = "0.10.0", optional = true }
gtk-rs = { version = "0.14.0", features = ["v3_22"], package = "gtk", optional = true }
glib-sys = { version = "0.14.0", optional = true }
gtk-sys = { version = "0.14.0", optional = true }
nix = { version = "0.18.0", optional = true }
x11rb = { version = "0.8.0", features = ["allow-unsafe-code", "present", "render", "randr", "xfixes", "xkb", "resource_manager", "cursor"], optional = true }

Expand All @@ -100,7 +96,7 @@ version = "0.3.44"
features = ["Window", "MouseEvent", "CssStyleDeclaration", "WheelEvent", "KeyEvent", "KeyboardEvent", "Navigator"]

[dev-dependencies]
piet-common = { version = "=0.4.1", features = ["png"] }
piet-common = { version = "=0.5.0-pre1", features = ["png"] }
static_assertions = "1.1.0"
test-env-log = { version = "0.2.5", features = ["trace"], default-features = false }
tracing-subscriber = "0.2.15"
Expand Down
26 changes: 12 additions & 14 deletions druid-shell/src/backend/gtk/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

//! GTK implementation of features at the application scope.

use gio::prelude::ApplicationExtManual;
use gio::{ApplicationExt, ApplicationFlags, Cancellable};
use gtk::{Application as GtkApplication, GtkApplicationExt};
use gtk::gio::prelude::ApplicationExtManual;
use gtk::gio::{ApplicationFlags, Cancellable};
use gtk::Application as GtkApplication;

use gtk::prelude::{ApplicationExt, GtkApplicationExt};

use crate::application::AppHandler;

Expand All @@ -31,18 +33,15 @@ pub(crate) struct Application {
impl Application {
pub fn new() -> Result<Application, Error> {
// TODO: we should give control over the application ID to the user
let gtk_app = match GtkApplication::new(
let gtk_app = GtkApplication::new(
Some("com.github.linebender.druid"),
// TODO we set this to avoid connecting to an existing running instance
// of "com.github.linebender.druid" after which we would never receive
// the "Activate application" below. See pull request druid#384
// Which shows another way once we have in place a mechanism for
// communication with remote instances.
ApplicationFlags::NON_UNIQUE,
) {
Ok(app) => app,
Err(err) => return Err(Error::BoolError(err)),
};
);

gtk_app.connect_activate(|_app| {
tracing::info!("gtk: Activated application");
Expand All @@ -61,12 +60,11 @@ impl Application {
}

pub fn run(self, _handler: Option<Box<dyn AppHandler>>) {
// TODO: should we pass the command line arguments?
self.gtk_app.run(&[]);
self.gtk_app.run();
}

pub fn quit(&self) {
match self.gtk_app.get_active_window() {
match self.gtk_app.active_window() {
None => {
// no application is running, main is not running
}
Expand All @@ -79,12 +77,12 @@ impl Application {

pub fn clipboard(&self) -> Clipboard {
Clipboard {
selection: gdk::SELECTION_CLIPBOARD,
selection: gtk::gdk::SELECTION_CLIPBOARD,
}
}

pub fn get_locale() -> String {
let mut locale: String = glib::get_language_names()[0].as_str().into();
let mut locale: String = gtk::glib::language_names()[0].as_str().into();
// This is done because the locale parsing library we use expects an unicode locale, but these vars have an ISO locale
if let Some(idx) = locale.chars().position(|c| c == '.' || c == '@') {
locale.truncate(idx);
Expand All @@ -96,7 +94,7 @@ impl Application {
impl crate::platform::linux::ApplicationExt for crate::Application {
fn primary_clipboard(&self) -> crate::Clipboard {
crate::Clipboard(Clipboard {
selection: gdk::SELECTION_PRIMARY,
selection: gtk::gdk::SELECTION_PRIMARY,
})
}
}
42 changes: 22 additions & 20 deletions druid-shell/src/backend/gtk/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//! Interactions with the system pasteboard on GTK+.

use gdk::Atom;
use gtk::gdk::Atom;
use gtk::{TargetEntry, TargetFlags};

use crate::clipboard::{ClipboardFormat, FormatId};
Expand All @@ -36,8 +36,8 @@ pub struct Clipboard {
impl std::fmt::Debug for Clipboard {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = match self.selection {
gdk::SELECTION_PRIMARY => "Primary",
gdk::SELECTION_CLIPBOARD => "Clipboard",
gtk::gdk::SELECTION_PRIMARY => "Primary",
gtk::gdk::SELECTION_CLIPBOARD => "Clipboard",
_ => "(other)",
};
f.debug_tuple("Clipboard").field(&name).finish()
Expand All @@ -49,8 +49,8 @@ impl Clipboard {
pub fn put_string(&mut self, string: impl AsRef<str>) {
let string = string.as_ref().to_string();

let display = gdk::Display::get_default().unwrap();
let clipboard = gtk::Clipboard::get_for_display(&display, &self.selection);
let display = gtk::gdk::Display::default().unwrap();
let clipboard = gtk::Clipboard::for_display(&display, &self.selection);

let targets: Vec<TargetEntry> = CLIPBOARD_TARGETS
.iter()
Expand All @@ -60,15 +60,16 @@ impl Clipboard {

clipboard.set_with_data(&targets, move |_, selection, _| {
const STRIDE_BITS: i32 = 8;
selection.set(&selection.get_target(), STRIDE_BITS, string.as_bytes());
selection.set(&selection.target(), STRIDE_BITS, string.as_bytes());
});
}

/// Put multi-format data on the system clipboard.
pub fn put_formats(&mut self, formats: &[ClipboardFormat]) {
let entries = make_entries(formats);
let display = gdk::Display::get_default().unwrap();
let clipboard = gtk::Clipboard::get_for_display(&display, &self.selection);
let display = gtk::gdk::Display::default().unwrap();
let clipboard = gtk::Clipboard::for_display(&display, &self.selection);

// this is gross: we need to reclone all the data in formats in order
// to move it into the closure. :/
let formats = formats.to_owned();
Expand All @@ -95,13 +96,13 @@ impl Clipboard {

/// Get a string from the system clipboard, if one is available.
pub fn get_string(&self) -> Option<String> {
let display = gdk::Display::get_default().unwrap();
let clipboard = gtk::Clipboard::get_for_display(&display, &self.selection);
let display = gtk::gdk::Display::default().unwrap();
let clipboard = gtk::Clipboard::for_display(&display, &self.selection);

for target in &CLIPBOARD_TARGETS {
let atom = Atom::intern(target);
if let Some(selection) = clipboard.wait_for_contents(&atom) {
return String::from_utf8(selection.get_data()).ok();
return String::from_utf8(selection.data()).ok();
}
}

Expand All @@ -111,8 +112,9 @@ impl Clipboard {
/// Given a list of supported clipboard types, returns the supported type which has
/// highest priority on the system clipboard, or `None` if no types are supported.
pub fn preferred_format(&self, formats: &[FormatId]) -> Option<FormatId> {
let display = gdk::Display::get_default().unwrap();
let clipboard = gtk::Clipboard::get_for_display(&display, &self.selection);
let display = gtk::gdk::Display::default().unwrap();
let clipboard = gtk::Clipboard::for_display(&display, &self.selection);

let targets = clipboard.wait_for_targets()?;
let format_atoms = formats
.iter()
Expand All @@ -131,17 +133,17 @@ impl Clipboard {
/// It is recommended that the `fmt` argument be a format returned by
/// [`Clipboard::preferred_format`]
pub fn get_format(&self, format: FormatId) -> Option<Vec<u8>> {
let display = gdk::Display::get_default().unwrap();
let clipboard = gtk::Clipboard::get_for_display(&display, &self.selection);
let display = gtk::gdk::Display::default().unwrap();
let clipboard = gtk::Clipboard::for_display(&display, &self.selection);

let atom = Atom::intern(format);
clipboard
.wait_for_contents(&atom)
.map(|data| data.get_data())
clipboard.wait_for_contents(&atom).map(|data| data.data())
}

pub fn available_type_names(&self) -> Vec<String> {
let display = gdk::Display::get_default().unwrap();
let clipboard = gtk::Clipboard::get_for_display(&display, &self.selection);
let display = gtk::gdk::Display::default().unwrap();
let clipboard = gtk::Clipboard::for_display(&display, &self.selection);

let targets = clipboard.wait_for_targets().unwrap_or_default();
targets
.iter()
Expand Down
6 changes: 4 additions & 2 deletions druid-shell/src/backend/gtk/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use std::ffi::OsString;

use anyhow::anyhow;
use gtk::{FileChooserAction, FileChooserExt, FileFilter, NativeDialogExt, ResponseType, Window};
use gtk::{FileChooserAction, FileFilter, ResponseType, Window};

use gtk::prelude::{FileChooserExt, NativeDialogExt};

use crate::dialog::{FileDialogOptions, FileDialogType, FileSpec};
use crate::Error;
Expand Down Expand Up @@ -96,7 +98,7 @@ pub(crate) fn get_file_dialog_path(
let result = dialog.run();

let result = match result {
ResponseType::Accept => match dialog.get_filename() {
ResponseType::Accept => match dialog.filename() {
Some(path) => Ok(path.into_os_string()),
None => Err(anyhow!("No path received for filename")),
},
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/gtk/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::fmt;

use glib::{BoolError, Error as GLibError};
use gtk::glib::{BoolError, Error as GLibError};

/// GTK backend errors.
#[derive(Debug, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions druid-shell/src/backend/gtk/keycodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

//! GTK code handling.

use gdk::keys::constants::*;
use gtk::gdk::keys::constants::*;

pub use super::super::shared::hardware_keycode_to_code;
use crate::keyboard_types::{Key, Location};

pub type RawKey = gdk::keys::Key;
pub type RawKey = gtk::gdk::keys::Key;

#[allow(clippy::just_underscores_and_digits, non_upper_case_globals)]
pub fn raw_key_to_key(raw: RawKey) -> Option<Key> {
Expand Down
10 changes: 6 additions & 4 deletions druid-shell/src/backend/gtk/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

//! GTK implementation of menus.

use gdk::ModifierType;
use gtk::gdk::ModifierType;
use gtk::{
AccelGroup, GtkMenuExt, GtkMenuItemExt, Menu as GtkMenu, MenuBar as GtkMenuBar,
MenuItem as GtkMenuItem, MenuShellExt, SeparatorMenuItemBuilder, WidgetExt,
AccelGroup, Menu as GtkMenu, MenuBar as GtkMenuBar, MenuItem as GtkMenuItem,
SeparatorMenuItemBuilder,
};

use gtk::prelude::{GtkMenuExt, GtkMenuItemExt, MenuShellExt, WidgetExt};

use super::keycodes;
use super::window::WindowHandle;
use crate::common_util::strip_access_key;
Expand Down Expand Up @@ -164,7 +166,7 @@ fn register_accelerator(item: &GtkMenuItem, accel_group: &AccelGroup, menu_key:
);
}

fn modifiers_to_gdk_modifier_type(raw_modifiers: RawMods) -> gdk::ModifierType {
fn modifiers_to_gdk_modifier_type(raw_modifiers: RawMods) -> ModifierType {
let mut result = ModifierType::empty();

let modifiers: Modifiers = raw_modifiers.into();
Expand Down
14 changes: 7 additions & 7 deletions druid-shell/src/backend/gtk/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
//! GTK Monitors and Screen information.

use crate::screen::Monitor;
use gdk::Display;
use gtk::gdk::{Display, DisplayManager, Rectangle};
use kurbo::{Point, Rect, Size};

fn translate_gdk_rectangle(r: gdk::Rectangle) -> Rect {
fn translate_gdk_rectangle(r: Rectangle) -> Rect {
Rect::from_origin_size(
Point::new(r.x as f64, r.y as f64),
Size::new(r.width as f64, r.height as f64),
)
}

fn translate_gdk_monitor(mon: gdk::Monitor) -> Monitor {
let area = translate_gdk_rectangle(mon.get_geometry());
fn translate_gdk_monitor(mon: gtk::gdk::Monitor) -> Monitor {
let area = translate_gdk_rectangle(mon.geometry());
Monitor::new(
mon.is_primary(),
area,
Expand All @@ -37,12 +37,12 @@ fn translate_gdk_monitor(mon: gdk::Monitor) -> Monitor {
}

pub(crate) fn get_monitors() -> Vec<Monitor> {
gdk::DisplayManager::get()
DisplayManager::get()
.list_displays()
.iter()
.flat_map(|display: &Display| {
(0..display.get_n_monitors())
.map(move |i| display.get_monitor(i).map(translate_gdk_monitor))
(0..display.n_monitors())
.map(move |i| display.monitor(i).map(translate_gdk_monitor))
.flatten()
})
.collect()
Expand Down
Loading