revert X Property change, and cleanup formatting

This commit is contained in:
Ashley Wulber 2021-12-29 17:31:01 -05:00
parent 5a4a802751
commit 65f43a9300
32 changed files with 459 additions and 429 deletions

View file

@ -1,12 +1,12 @@
use std::cell::RefCell;
use std::rc::Rc;
use glib::{FromVariant, ParamFlags, ParamSpec, ToVariant, Value, Variant, VariantTy};
use gtk4::glib;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use once_cell::sync::Lazy;
use std::cell::RefCell;
use std::rc::Rc;
use super::AppGroupData;
// Object holding the state
@ -142,7 +142,7 @@ impl ObjectImpl for AppGroup {
.get::<Variant>()
.expect("The icon needs to be a Variant"),
)
.expect("The icon variant needs to be a Vec<String>");
.expect("The icon variant needs to be a Vec<String>");
self.data.borrow_mut().app_names = appnames;
}
_ => unimplemented!(),

View file

@ -1,5 +1,3 @@
mod imp;
use glib::Object;
use glib::ObjectExt;
use glib::ToVariant;
@ -7,6 +5,8 @@ use gtk4::glib;
use gtk4::subclass::prelude::*;
use serde::{Deserialize, Serialize};
mod imp;
glib::wrapper! {
pub struct AppGroup(ObjectSubclass<imp::AppGroup>);
}
@ -20,7 +20,7 @@ impl AppGroup {
("icon", &data.icon),
("category", &data.category),
])
.expect("Failed to create `ApplicationObject`.");
.expect("Failed to create `ApplicationObject`.");
if let Err(e) = self_.set_property("appnames", data.app_names.to_variant()) {
println!("failed to set category icon property");
dbg!(e);

View file

@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GridItem" parent="GtkBox">
<property name="orientation">vertical</property>
<property name="halign">center</property>
<property name="hexpand">true</property>
<property name="margin-top">4</property>
<property name="margin-start">4</property>
<property name="margin-end">4</property>
<property name="margin-bottom">4</property>
<child>
<object class="GtkImage" id="image">
<property name="margin-top">4</property>
<property name="margin-bottom">4</property>
<property name="pixel-size">64</property>
</object>
</child>
<child>
<object class="GtkLabel" id="name">
<template class="GridItem" parent="GtkBox">
<property name="orientation">vertical</property>
<property name="halign">center</property>
<property name="ellipsize">end</property>
<style>
<class name="title-5" />
</style>
</object>
</child>
</template>
<property name="hexpand">true</property>
<property name="margin-top">4</property>
<property name="margin-start">4</property>
<property name="margin-end">4</property>
<property name="margin-bottom">4</property>
<child>
<object class="GtkImage" id="image">
<property name="margin-top">4</property>
<property name="margin-bottom">4</property>
<property name="pixel-size">64</property>
</object>
</child>
<child>
<object class="GtkLabel" id="name">
<property name="halign">center</property>
<property name="ellipsize">end</property>
<style>
<class name="title-5"/>
</style>
</object>
</child>
</template>
</interface>

View file

@ -1,10 +1,10 @@
use std::cell::Cell;
use gtk4 as gtk;
use gtk::CompositeTemplate;
use gtk::glib;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk4 as gtk;
use std::cell::Cell;
use gtk::CompositeTemplate;
#[derive(Debug, Default, CompositeTemplate)]
#[template(file = "grid_item.ui")]
@ -32,5 +32,7 @@ impl ObjectSubclass for GridItem {
}
impl ObjectImpl for GridItem {}
impl WidgetImpl for GridItem {}
impl BoxImpl for GridItem {}

View file

@ -1,17 +1,18 @@
use crate::app_group::AppGroup;
use gdk4::ContentProvider;
use gdk4::Display;
use gio::File;
use gio::Icon;
use gtk::{gio, glib};
use gtk4 as gtk;
use gtk4::traits::WidgetExt;
use gtk4::DragSource;
use gtk4::IconTheme;
mod imp;
use gtk4::traits::WidgetExt;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{gio, glib};
use crate::app_group::AppGroup;
mod imp;
glib::wrapper! {
pub struct GridItem(ObjectSubclass<imp::GridItem>)

View file

@ -1,18 +1,18 @@
mod app_group;
mod grid_item;
mod utils;
mod window;
use gtk::gdk::Display;
use gtk::prelude::*;
use gtk4 as gtk;
use gtk4::CssProvider;
use gtk4::StyleContext;
use gtk::gdk::Display;
use gtk::prelude::*;
use once_cell::sync::OnceCell;
use x11rb::rust_connection::RustConnection;
use window::Window;
mod app_group;
mod grid_item;
mod utils;
mod window;
static X11_CONN: OnceCell<RustConnection> = OnceCell::new();
fn main() {

View file

@ -2,12 +2,15 @@ child:hover {
transition: 100ms;
background: #888888;
}
child {
border-radius: 5px;
}
gridview {
background: #333333;
}
window {
background: #333333;
border-radius: 15px;

View file

@ -1,7 +1,7 @@
use gtk4::ScrolledWindow;
use std::path::PathBuf;
use gtk4::glib;
use gtk4::ScrolledWindow;
pub fn data_path() -> PathBuf {
let mut path = glib::user_data_dir();

View file

@ -1,13 +1,13 @@
use gtk4 as gtk;
use gtk4::ScrolledWindow;
use std::fs::File;
use glib::signal::Inhibit;
use glib::subclass::InitializingObject;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{gio, glib};
use gtk::{CompositeTemplate, GridView, SearchEntry};
use gtk4 as gtk;
use gtk4::ScrolledWindow;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use once_cell::sync::OnceCell;
use crate::app_group::AppGroup;
@ -45,6 +45,7 @@ impl ObjectSubclass for Window {
obj.init_template();
}
}
// Trait shared by all GObjects
impl ObjectImpl for Window {
fn constructed(&self, obj: &Self::Type) {
@ -58,6 +59,7 @@ impl ObjectImpl for Window {
obj.setup_factory();
}
}
// Trait shared by all widgets
impl WidgetImpl for Window {}

View file

@ -1,31 +1,33 @@
mod imp;
use crate::app_group::AppGroup;
use crate::app_group::AppGroupData;
use crate::grid_item::GridItem;
use crate::utils::data_path;
use crate::utils::set_group_scroll_policy;
use crate::X11_CONN;
use std::fs::File;
use gdk4::Rectangle;
use gdk4_x11::X11Display;
use gdk4_x11::X11Surface;
use glib::FromVariant;
use glib::Object;
use glib::Variant;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{gio, glib};
use gtk::{Application, SignalListItemFactory};
use gtk4 as gtk;
use gtk4::Dialog;
use gtk4::Entry;
use gtk4::Label;
use libcosmic::x;
use std::fs::File;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use x11rb::connection::Connection;
use x11rb::protocol::xproto;
use x11rb::protocol::xproto::ConnectionExt as OtherConnectionExt;
use x11rb::protocol::xproto::*;
use x11rb::wrapper::ConnectionExt;
use x11rb::protocol::xproto::ConnectionExt;
use libcosmic::x;
use crate::app_group::AppGroup;
use crate::app_group::AppGroupData;
use crate::grid_item::GridItem;
use crate::utils::data_path;
use crate::utils::set_group_scroll_policy;
use crate::X11_CONN;
mod imp;
glib::wrapper! {
pub struct Window(ObjectSubclass<imp::Window>)
@ -170,10 +172,10 @@ impl Window {
category: "".to_string(),
}),
]
.iter()
.for_each(|group| {
group_model.append(group);
});
.iter()
.for_each(|group| {
group_model.append(group);
});
let group_selection = gtk4::SingleSelection::new(Some(&group_model));
imp.group_grid_view.set_model(Some(&group_selection));
}
@ -407,27 +409,15 @@ impl Window {
.downcast::<X11Display>()
.expect("Failed to downgrade X11 Display.");
xdisplay.error_trap_push();
let conn = X11_CONN.get().expect("Failed to get X11 connection");
let window_type_atom = conn
.intern_atom(false, b"_NET_WM_WINDOW_TYPE")
.unwrap()
.reply()
.unwrap()
.atom;
let dock_type_atom = conn
.intern_atom(false, b"_NET_WM_WINDOW_TYPE_DIALOG")
.unwrap()
.reply()
.unwrap()
.atom;
conn.change_property32(
PropMode::REPLACE,
surface.xid().try_into().unwrap(),
window_type_atom,
AtomEnum::ATOM,
&[dock_type_atom],
)
.unwrap();
unsafe {
x::change_property(
&display,
&surface,
"_NET_WM_WINDOW_TYPE",
x::PropMode::Replace,
&[x::Atom::new(&display, "_NET_WM_WINDOW_TYPE_DIALOG").unwrap()],
);
}
let resize = glib::clone!(@weak window => move || {
let s = window.surface().expect("Failed to get Surface for Window");
let height = window.height();

View file

@ -1,66 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="LauncherWindow" parent="GtkApplicationWindow">
<property name="width-request">1200</property>
<property name="title">Pop App Library</property>
<property name="decorated">false</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<template class="LauncherWindow" parent="GtkApplicationWindow">
<property name="width-request">1200</property>
<property name="title">Pop App Library</property>
<property name="decorated">false</property>
<child>
<object class="GtkSearchEntry" id="entry">
<property name="width-request">300</property>
<property name="halign">center</property>
<property name="margin-bottom">12</property>
<property name="margin-top">12</property>
</object>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<child>
<object class="GtkSearchEntry" id="entry">
<property name="width-request">300</property>
<property name="halign">center</property>
<property name="margin-bottom">12</property>
<property name="margin-top">12</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hscrollbar-policy">never</property>
<property name="min-content-height">500</property>
<property name="vexpand">true</property>
<property name="margin-top">12</property>
<child>
<object class="GtkGridView" id="app_grid_view">
<property name="min-columns">7</property>
<property name="max-columns">7</property>
<property name="single-click-activate">false</property>
<property name="enable-rubberband">false</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSeparator">
<property name="orientation">horizontal</property>
<property name="hexpand">true</property>
<property name="margin-bottom">12</property>
<property name="margin-top">12</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow" id="group_scroll_window">
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">never</property>
<property name="propagate-natural-height">true</property>
<property name="min-content-height">150</property>
<property name="max-content-height">300</property>
<child>
<object class="GtkGridView" id="group_grid_view">
<property name="min-columns">8</property>
<property name="max-columns">8</property>
<property name="single-click-activate">false</property>
<property name="enable-rubberband">false</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hscrollbar-policy">never</property>
<property name="min-content-height">500</property>
<property name="vexpand">true</property>
<property name="margin-top">12</property>
<child>
<object class="GtkGridView" id="app_grid_view">
<property name="min-columns">7</property>
<property name="max-columns">7</property>
<property name="single-click-activate">false</property>
<property name="enable-rubberband">false</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSeparator">
<property name="orientation">horizontal</property>
<property name="hexpand">true</property>
<property name="margin-bottom">12</property>
<property name="margin-top">12</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow" id="group_scroll_window">
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">never</property>
<property name="propagate-natural-height">true</property>
<property name="min-content-height">150</property>
<property name="max-content-height">300</property>
<child>
<object class="GtkGridView" id="group_grid_view">
<property name="min-columns">8</property>
<property name="max-columns">8</property>
<property name="single-click-activate">false</property>
<property name="enable-rubberband">false</property>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</template>
</interface>