Skip to content

Instantly share code, notes, and snippets.

let list_store = gio::ListStore::new(glib::Object::static_type());
let obj: glib::Object = glib::Object::new();
unsafe {
// Use set_data so we don't have to implement a subclass with a real property.
obj.set_data::<String>("hoy", "nice".to_string());
}
list_store.append(&obj);
let v: Vec<glib::Object> = list_store.into_iter().map(|x| {x.unwrap().clone()}).collect();
unsafe {
let o = v[0].data::<String>("hoy").expect("hoy").as_ref();
@saivert
saivert / gettext-search-path.rs
Created August 2, 2023 20:30
gettext-rs development locale dir search path
fn main() -> gtk::glib::ExitCode {
let mut textdomain = gettextrs::TextDomain::new(GETTEXT_PACKAGE);
if cfg!(debug_assertions) {
// Add extra search path for debug builds so we don't have to install
textdomain = textdomain.prepend("../locale-test");
}
_ = textdomain.init().map_err(|x|{
// TranslationNotFound is not a fatal error, fallback to msgid (english)
if !matches!(x, TextDomainError::TranslationNotFound(_)) {
panic!("Unable to setup gettext!")
/*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
use crate::{application::PwvucontrolApplication, pwnodeobject::PwNodeObject};
use glib::{self, clone, ParamSpec, Properties, Value};
use gtk::{gio, prelude::*, subclass::prelude::*};
use std::cell::RefCell;
error: failed to select a version for `libspa-sys`.
... required by package `wireplumber v0.1.0 (https://github.com/arcnmx/wireplumber.rs.git?rev=ff1a07c43a9ee1859b2b197d253f2b19cb7763e6#ff1a07c4)`
... which satisfies git dependency `wireplumber` (locked to 0.1.0) of package `pwvucontrol v0.1.0 (/home/saivert/Projects/pwvucontrol)`
versions that meet the requirements `^0.6` (locked to 0.6.0) are: 0.6.0
the package `libspa-sys` links to the native library `libspa-0.2`, but it conflicts with a previous package which links to `libspa-0.2` as well:
package `libspa-sys v0.6.0 (https://gitlab.freedesktop.org/saivert/pipewire-rs?branch=format_parsing_test#5eea3a45)`
... which satisfies git dependency `spa_sys` of package `pipewire v0.6.0 (https://gitlab.freedesktop.org/saivert/pipewire-rs?branch=format_parsing_test#5eea3a45)`
... which satisfies git dependency `pipewire` of package `pwvucontrol v0.1.0 (/home/saivert/Projects/pwvucontrol)`
Only one package in the dependency graph may specify the same
item.property_expression("item")
.chain_property::<wp::pw::Device>("properties")
.chain_closure::<glib::GString>(closure!(|_: Option<glib::Object>, props: wp::pw::Properties| {
props.get("device.description").unwrap()
}))
.bind(&label, "label", gtk::Widget::NONE);
item.set_child(Some(&label));
// First some setup code
pub struct PwvucontrolApplication {
pub(crate) window: OnceCell<PwvucontrolWindow>,
}
impl ApplicationImpl for PwvucontrolApplication {
fn activate(&self) {
let window = self
.window
macro_rules! cstr {
($s:expr) => (
concat!($s, "\0") as *const str as *const [std::ffi::c_char] as *const std::ffi::c_char
);
}
#[macro_export]
macro_rules! wp_spa_pod_new_object {
($object_type_name:expr, $object_id_name:expr, $( $name:expr, $type:expr, $value:expr ),*) => {{
// Is this currently the only way to set enums without type information in the rust bindings (e.g from foreign code)
let t = glib::Type::from_name("WpMixerApiVolumeScale").unwrap();
let v = glib::Value::from_type(t);
unsafe {
glib::gobject_ffi::g_value_set_enum(v.as_ptr(), 1);
}
mixerapi.set_property("scale", v);
let test = dict.lookup::<HashMap<String, glib::Variant>>("channelVolumes");
if let Ok(Some(test)) = test {
for (index_str, v) in test.iter() {
let index: u32 = index_str.parse().expect("erroneous index");
let map: HashMap<String, glib::Variant> = v.get().unwrap();
let volume = map.get("volume").and_then(|x|x.get::<f64>());
let channelname = map.get("channel").and_then(|x|x.get::<String>()).unwrap_or_default();
let channel = t_audiochannel.find_value_from_short_name(&channelname);
if let (Some(c), Some(v)) = (channel, volume) {
// Boxed type guide
// Define the boxed type
#[derive(glib::Boxed, Clone, Default)]
#[boxed_type(name = "FloatVec")]
pub struct FloatVec(Vec<f32>);
impl FloatVec {
pub fn get(&self) -> Vec<f32> {
self.0.clone()