I want to make a webkit window and show it as my wallpaper.
I found a workaround to create a webkit2gtk window as follows.
// [dependencies]
// gtk = "0.16.0"
// gtk-layer-shell = "0.5"
// webkit2gtk = "1.1.0"
use gtk::gdk;
use gtk::prelude::*;
use gtk::Application;
use gtk::ApplicationWindow;
use webkit2gtk::WebViewExt;
fn main() {
let app = Application::new(None, Default::default());
app.connect_activate(move |app| {
let display = gdk::Display::default().unwrap();
for i in 0..display.n_monitors() {
let monitor = display.monitor(i).unwrap();
let gtk_window = ApplicationWindow::new(app);
gtk_window.set_default_size(1920, 1080);
let webview = webkit2gtk::WebView::new();
gtk_window.add(&webview);
webview.load_uri("http://localhost:8081");
// gtk_layer_shell::init_for_window(>k_window);
// gtk_layer_shell::set_layer(>k_window, gtk_layer_shell::Layer::Background);
// gtk_layer_shell::set_monitor(>k_window, &monitor);
gtk_window.show_all();
}
});
app.run();
}
The above code works fine and creates 2 webview windows (since I have 2 monitors). However, if I add some gtk_layer_shell operations to the code (as commented above), no window appears anywhere.
I'm wondering if this is some webkit2gtk bug or something wrong with my code.
The window you create with layer shell needs to have size set and the set_default_size
seems not doing its job.
Replace gtk_window.set_default_size(1920, 1080);
with gtk_window.set_size_request(1920, 1080);
and the window should show.
If you want to create fullscreen window with layer shell you can skip the size request and use anchors instead:
window.set_anchor(Edge::Left, true);
window.set_anchor(Edge::Right, true);
window.set_anchor(Edge::Top, true);
window.set_anchor(Edge::Bottom, true);