Skip to content

Commit

Permalink
[gtk] Fix breakage from updated gtk deps
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr committed Aug 21, 2020
1 parent 15f4fec commit 33206a8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions druid-shell/src/platform/gtk/keycodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

//! GTK code handling.
use gdk::enums::key::*;
use gdk::keys::constants::*;

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

pub type RawKey = gdk::enums::key::Key;
pub type RawKey = 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 Expand Up @@ -111,7 +111,7 @@ pub fn raw_key_to_location(raw: RawKey) -> Location {
}

#[allow(non_upper_case_globals)]
pub fn key_to_raw_key(src: &Key) -> Option<u32> {
pub fn key_to_raw_key(src: &Key) -> Option<RawKey> {
Some(match src {
Key::Escape => Escape,
Key::Backspace => BackSpace,
Expand Down
6 changes: 3 additions & 3 deletions druid-shell/src/platform/gtk/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Menu {
key,
enabled,
} => {
let item = GtkMenuItem::new_with_label(&name);
let item = GtkMenuItem::with_label(&name);
item.set_sensitive(enabled);

if let Some(k) = key {
Expand All @@ -110,7 +110,7 @@ impl Menu {
menu.append(&item);
}
MenuItem::SubMenu(name, submenu) => {
let item = GtkMenuItem::new_with_label(&name);
let item = GtkMenuItem::with_label(&name);
item.set_submenu(Some(&submenu.into_gtk_menu(handle, accel_group)));

menu.append(&item);
Expand Down Expand Up @@ -147,7 +147,7 @@ fn register_accelerator(item: &GtkMenuItem, accel_group: &AccelGroup, menu_key:
KbKey::Character(text) => text.chars().next().unwrap() as u32,
k => {
if let Some(gdk_key) = keycodes::key_to_raw_key(k) {
gdk_key
*gdk_key
} else {
log::warn!("Cannot map key {:?}", k);
return;
Expand Down
26 changes: 13 additions & 13 deletions druid-shell/src/platform/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ impl WindowBuilder {
// Get the scale factor based on the GTK reported DPI
let scale_factor = window
.get_display()
.map(|c| c.get_default_screen().get_resolution())
.unwrap_or(SCALE_TARGET_DPI)
.get_default_screen().get_resolution()
/ SCALE_TARGET_DPI;
let scale = Scale::new(scale_factor, scale_factor);
let area = ScaledArea::from_dp(self.size, scale);
Expand Down Expand Up @@ -327,7 +326,7 @@ impl WindowBuilder {
let surface = state.surface.try_borrow();
if let Ok(Some(surface)) = surface.as_ref().map(|s| s.as_ref()) {
if let Ok(mut invalid) = state.invalid.try_borrow_mut() {
let mut surface_context = cairo::Context::new(surface);
let surface_context = cairo::Context::new(surface);

// Clip to the invalid region, in order that our surface doesn't get
// messed up if there's any painting outside them.
Expand All @@ -337,10 +336,10 @@ impl WindowBuilder {
surface_context.clip();

surface_context.scale(scale.x(), scale.y());
let mut piet_context = Piet::new(&mut surface_context);
let mut piet_context = Piet::new(&surface_context);
handler_borrow.paint(&mut piet_context, &invalid);
if let Err(e) = piet_context.finish() {
eprintln!("piet error on render: {:?}", e);
log::error!("piet error on render: {:?}", e);
}

// Copy the entire surface to the drawing area (not just the invalid
Expand Down Expand Up @@ -726,14 +725,14 @@ impl WindowHandle {
let token = TimerToken::next();
let handle = self.clone();

gdk::threads_add_timeout(interval, move || {
glib::timeout_add_local(interval, move || {
if let Some(state) = handle.state.upgrade() {
if let Ok(mut handler_borrow) = state.handler.try_borrow_mut() {
handler_borrow.timer(token);
return false;
return glib::Continue(false);
}
}
true
glib::Continue(true)
});
token
}
Expand Down Expand Up @@ -893,7 +892,7 @@ fn run_idle(state: &Arc<WindowState>) -> glib::source::Continue {
}

fn make_gdk_cursor(cursor: &Cursor, gdk_window: &gdk::Window) -> Option<gdk::Cursor> {
gdk::Cursor::new_from_name(
gdk::Cursor::from_name(
&gdk_window.get_display(),
match cursor {
// cursor name values from https://www.w3.org/TR/css-ui-3/#cursor
Expand Down Expand Up @@ -981,9 +980,9 @@ fn make_key_event(key: &EventKey, repeat: bool, state: KeyState) -> KeyEvent {
let keyval = key.get_keyval();
let hardware_keycode = key.get_hardware_keycode();

let keycode = hardware_keycode_to_keyval(hardware_keycode).unwrap_or(keyval);
let keycode = hardware_keycode_to_keyval(hardware_keycode).unwrap_or_else(|| keyval.clone());

let text = gdk::keyval_to_unicode(keyval);
let text = gdk::keys::keyval_to_unicode(*keyval);
let mods = get_modifiers(key.get_state());
let key = keycodes::raw_key_to_key(keyval).unwrap_or_else(|| {
if let Some(c) = text {
Expand Down Expand Up @@ -1013,7 +1012,8 @@ fn make_key_event(key: &EventKey, repeat: bool, state: KeyState) -> KeyEvent {

/// Map a hardware keycode to a keyval by performing a lookup in the keymap and finding the
/// keyval with the lowest group and level
fn hardware_keycode_to_keyval(keycode: u16) -> Option<u32> {
fn hardware_keycode_to_keyval(keycode: u16) -> Option<keycodes::RawKey> {
use glib::translate::FromGlib;
unsafe {
let keymap = gdk_sys::gdk_keymap_get_default();

Expand All @@ -1036,7 +1036,7 @@ fn hardware_keycode_to_keyval(keycode: u16) -> Option<u32> {

let resolved_keyval = keys_slice.iter().enumerate().find_map(|(i, key)| {
if key.group == 0 && key.level == 0 {
Some(keyvals_slice[i])
Some(keycodes::RawKey::from_glib(keyvals_slice[i]))
} else {
None
}
Expand Down

0 comments on commit 33206a8

Please sign in to comment.