Skip to content

Commit

Permalink
chore(gtk): use the re-exported modules in gtk crate instead (#1042)
Browse files Browse the repository at this point in the history
* Switch to using re-exported modules in gtk

* Added change file
  • Loading branch information
dklassic authored Oct 23, 2023
1 parent f2299c2 commit 591fda8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changes/gtkreexport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Use `gtk`'s re-exported modules instead.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ base64 = "0.21"
javascriptcore-rs = { version = "=1.1.1", features = [ "v2_28" ] }
webkit2gtk = { version = "=2.0", features = [ "v2_38" ] }
webkit2gtk-sys = "=2.0"
gio = "0.18"
glib = "0.18"
gtk = "0.18"
gdk = "0.18"
soup3 = "0.5"
winit = { version = "0.29", package = "winit-gtk", features = [ "serde" ], optional = true }

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub enum Error {
target_os = "openbsd"
))]
#[error(transparent)]
GlibError(#[from] glib::Error),
GlibError(#[from] gtk::glib::Error),
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
Expand All @@ -123,7 +123,7 @@ pub enum Error {
target_os = "openbsd"
))]
#[error(transparent)]
GlibBoolError(#[from] glib::BoolError),
GlibBoolError(#[from] gtk::glib::BoolError),
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
Expand Down
4 changes: 2 additions & 2 deletions src/webview/webkitgtk/file_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ pub(crate) fn connect_drag_event(
let w = window;
webview.connect_drag_failed(move |_, _, _| {
if listener_ref.0(&w, FileDropEvent::Cancelled) {
glib::Propagation::Stop
gtk::glib::Propagation::Stop
} else {
glib::Propagation::Proceed
gtk::glib::Propagation::Proceed
}
});
}
12 changes: 5 additions & 7 deletions src/webview/webkitgtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use gdk::EventMask;
use gio::Cancellable;
use gtk::prelude::*;
use gtk::{gdk::EventMask, gio::Cancellable, prelude::*};
#[cfg(any(debug_assertions, feature = "devtools"))]
use std::sync::atomic::{AtomicBool, Ordering};
use std::{
Expand Down Expand Up @@ -260,11 +258,11 @@ impl InnerWebView {

// Transparent
if attributes.transparent {
webview.set_background_color(&gdk::RGBA::new(0., 0., 0., 0.));
webview.set_background_color(&gtk::gdk::RGBA::new(0., 0., 0., 0.));
} else {
// background color
if let Some(background_color) = attributes.background_color {
webview.set_background_color(&gdk::RGBA::new(
webview.set_background_color(&gtk::gdk::RGBA::new(
background_color.0 as _,
background_color.1 as _,
background_color.2 as _,
Expand Down Expand Up @@ -444,7 +442,7 @@ impl InnerWebView {
}

pub fn set_background_color(&self, background_color: RGBA) -> Result<()> {
self.webview.set_background_color(&gdk::RGBA::new(
self.webview.set_background_color(&gtk::gdk::RGBA::new(
background_color.0 as _,
background_color.1 as _,
background_color.2 as _,
Expand Down Expand Up @@ -479,7 +477,7 @@ impl InnerWebView {
webkit2gtk::WebsiteDataManagerExtManual::clear(
&data_manger,
webkit2gtk::WebsiteDataTypes::ALL,
glib::TimeSpan::from_seconds(0),
gtk::glib::TimeSpan::from_seconds(0),
None::<&Cancellable>,
|_| {},
);
Expand Down
22 changes: 12 additions & 10 deletions src/webview/webkitgtk/synthetic_mouse_events.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::{cell::RefCell, rc::Rc};

use gdk::{EventButton, ModifierType};
use gtk::prelude::*;
use gtk::{
gdk::{EventButton, ModifierType},
prelude::*,
};
use webkit2gtk::{WebView, WebViewExt};

pub fn setup(webview: &WebView) {
Expand All @@ -17,7 +19,7 @@ pub fn setup(webview: &WebView) {
bf_state_c.set(BACK);
webview.run_javascript(
&create_js_mouse_event(event, true, &bf_state_c),
None::<&gio::Cancellable>,
None::<&gtk::gio::Cancellable>,
|_| {},
);
}
Expand All @@ -27,17 +29,17 @@ pub fn setup(webview: &WebView) {
bf_state_c.set(FORWARD);
webview.run_javascript(
&create_js_mouse_event(event, true, &bf_state_c),
None::<&gio::Cancellable>,
None::<&gtk::gio::Cancellable>,
|_| {},
);
}
_ => {}
}

if inhibit {
glib::Propagation::Stop
gtk::glib::Propagation::Stop
} else {
glib::Propagation::Proceed
gtk::glib::Propagation::Proceed
}
});

Expand All @@ -51,7 +53,7 @@ pub fn setup(webview: &WebView) {
bf_state_c.remove(BACK);
webview.run_javascript(
&create_js_mouse_event(event, false, &bf_state_c),
None::<&gio::Cancellable>,
None::<&gtk::gio::Cancellable>,
|_| {},
);
}
Expand All @@ -61,16 +63,16 @@ pub fn setup(webview: &WebView) {
bf_state_c.remove(FORWARD);
webview.run_javascript(
&create_js_mouse_event(event, false, &bf_state_c),
None::<&gio::Cancellable>,
None::<&gtk::gio::Cancellable>,
|_| {},
);
}
_ => {}
}
if inhibit {
glib::Propagation::Stop
gtk::glib::Propagation::Stop
} else {
glib::Propagation::Proceed
gtk::glib::Propagation::Proceed
}
});
}
Expand Down
12 changes: 7 additions & 5 deletions src/webview/webkitgtk/undecorated_resizing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::application::platform::unix::*;
use gdk::{Cursor, WindowEdge};
use gtk::prelude::*;
use gtk::{
gdk::{Cursor, WindowEdge},
prelude::*,
};
use webkit2gtk::WebView;

pub fn setup(webview: &WebView) {
Expand Down Expand Up @@ -37,7 +39,7 @@ pub fn setup(webview: &WebView) {
}
}
}
glib::Propagation::Proceed
gtk::glib::Propagation::Proceed
});
webview.connect_button_press_event(move |webview, event| {
if event.button() == 1 {
Expand All @@ -63,7 +65,7 @@ pub fn setup(webview: &WebView) {
}
}
}
glib::Propagation::Proceed
gtk::glib::Propagation::Proceed
});
webview.connect_touch_event(|webview, event| {
// This one should be GtkBox
Expand Down Expand Up @@ -96,6 +98,6 @@ pub fn setup(webview: &WebView) {
}
}
}
glib::Propagation::Proceed
gtk::glib::Propagation::Proceed
});
}
8 changes: 4 additions & 4 deletions src/webview/webkitgtk/web_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
webview::{web_context::WebContextData, RequestAsyncResponder},
Error,
};
use glib::FileError;
use gtk::glib::FileError;
use http::{header::CONTENT_TYPE, Request, Response as HttpResponse};
use std::{
borrow::Cow,
Expand Down Expand Up @@ -362,7 +362,7 @@ where
let http_request = match http_request.body(body) {
Ok(req) => req,
Err(_) => {
request.finish_error(&mut glib::Error::new(
request.finish_error(&mut gtk::glib::Error::new(
// TODO: use UriError when we can use 2_66 webkit2gtk feature flag
FileError::Exist,
"Could not get uri.",
Expand All @@ -375,7 +375,7 @@ where
let responder: Box<dyn FnOnce(HttpResponse<Cow<'static, [u8]>>)> =
Box::new(move |http_response| {
let buffer = http_response.body();
let input = gio::MemoryInputStream::from_bytes(&glib::Bytes::from(buffer));
let input = gtk::gio::MemoryInputStream::from_bytes(&gtk::glib::Bytes::from(buffer));
let content_type = http_response
.headers()
.get(CONTENT_TYPE)
Expand All @@ -400,7 +400,7 @@ where

handler(http_request, RequestAsyncResponder { responder });
} else {
request.finish_error(&mut glib::Error::new(
request.finish_error(&mut gtk::glib::Error::new(
FileError::Exist,
"Could not get uri.",
));
Expand Down

0 comments on commit 591fda8

Please sign in to comment.