focus windows using launcher IPC

This commit is contained in:
Ashley Wulber 2021-11-30 16:15:06 -05:00 committed by Jeremy Soller
parent 19f003f942
commit 54b762dbab
18 changed files with 350 additions and 276 deletions

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="ApplicationRow" parent="GtkBox">
<property name="orientation">horizontal</property>
<property name="spacing">12</property>
<property name="margin-start">4</property>
<property name="margin-end">4</property>
<property name="hexpand">true</property>
<child>
<object class="GtkImage" id="categoryimage">
<property name="pixel-size">20</property>
</object>
</child>
<child>
<object class="GtkImage" id="image">
<property name="margin-top">4</property>
<property name="margin-bottom">4</property>
<property name="pixel-size">36</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="halign">fill</property>
<property name="hexpand">true</property>
<property name="margin-top">4</property>
<property name="margin-end">4</property>
<property name="margin-bottom">4</property>
<child>
<object class="GtkLabel" id="name">
<property name="halign">start</property>
<style>
<class name="title-4" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="description">
<property name="halign">start</property>
<property name="wrap">True</property>
<style>
<class name="body" />
</style>
</object>
</child>
</object>
</child>
<child type="end">
<object class="GtkLabel" id="shortcut">
<property name="halign">end</property>
<property name="wrap">false</property>
<style>
<class name="body" />
</style>
</object>
</child>
</template>
</interface>

View file

@ -0,0 +1,40 @@
use gtk::glib;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk4 as gtk;
use gtk::CompositeTemplate;
#[derive(Debug, Default, CompositeTemplate)]
#[template(file = "application_row.ui")]
pub struct ApplicationRow {
#[template_child]
pub name: TemplateChild<gtk::Label>,
#[template_child]
pub description: TemplateChild<gtk::Label>,
#[template_child]
pub shortcut: TemplateChild<gtk::Label>,
#[template_child]
pub image: TemplateChild<gtk::Image>,
#[template_child]
pub categoryimage: TemplateChild<gtk::Image>,
}
#[glib::object_subclass]
impl ObjectSubclass for ApplicationRow {
const NAME: &'static str = "ApplicationRow";
type Type = super::ApplicationRow;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
Self::bind_template(klass);
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for ApplicationRow {}
impl WidgetImpl for ApplicationRow {}
impl BoxImpl for ApplicationRow {}

View file

@ -0,0 +1,79 @@
use crate::icon_source;
use glib::FromVariant;
use glib::Variant;
use gtk4 as gtk;
mod imp;
use crate::ApplicationObject;
use gtk::glib;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
glib::wrapper! {
pub struct ApplicationRow(ObjectSubclass<imp::ApplicationRow>)
@extends gtk::Widget, gtk::Box;
}
impl Default for ApplicationRow {
fn default() -> Self {
Self::new()
}
}
impl ApplicationRow {
pub fn new() -> Self {
glib::Object::new(&[]).expect("Failed to create ApplicationRow")
}
pub fn set_app_info(&self, app_obj: ApplicationObject) {
let self_ = imp::ApplicationRow::from_instance(self);
if let Ok(name) = app_obj.property("name") {
self_.name.set_text(
&name
.get::<String>()
.expect("Property name needs to be a String."),
);
}
if let Ok(desc) = app_obj.property("description") {
self_.description.set_text(
&desc
.get::<String>()
.expect("Property description needs to be a String."),
);
}
if let Ok(icon) = app_obj.property("icon") {
if let Ok(icon) = icon.get::<Variant>() {
let icon = match <(i32, String)>::from_variant(&icon) {
Some((i_type, name)) if i_type == pop_launcher::IconSource::Name as i32 => {
Some(pop_launcher::IconSource::Name(name.into()))
}
Some((i_type, name)) if i_type == pop_launcher::IconSource::Mime as i32 => {
Some(pop_launcher::IconSource::Mime(name.into()))
}
_ => None,
};
icon_source(&self_.image, &icon);
}
}
if let Ok(icon) = app_obj.property("categoryicon") {
if let Ok(icon) = icon.get::<Variant>() {
let icon = match <(i32, String)>::from_variant(&icon) {
Some((i_type, name)) if i_type == pop_launcher::IconSource::Name as i32 => {
Some(pop_launcher::IconSource::Name(name.into()))
}
Some((i_type, name)) if i_type == pop_launcher::IconSource::Mime as i32 => {
Some(pop_launcher::IconSource::Mime(name.into()))
}
_ => None,
};
icon_source(&self_.categoryimage, &icon);
}
}
}
pub fn set_shortcut(&self, indx: u32) {
let self_ = imp::ApplicationRow::from_instance(self);
self_.shortcut.set_text(&format!("Ctrl + {}", indx));
}
}