Don't use xpm, but png
Kinda fixes #1 Load times seem to be slightly higher though, because of png decoding, but this shouldn't be an issue, since pngs are only loaded on startup and preference save, not on volume meter updates.
This commit is contained in:
parent
94eac03ca1
commit
e401daca33
@ -3,9 +3,6 @@ name = "pnmixer-rs"
|
||||
version = "0.1.0"
|
||||
authors = ["Julian Ospald <hasufell@posteo.de>"]
|
||||
|
||||
[build-dependencies]
|
||||
gcc = "^0.3.0"
|
||||
|
||||
[dependencies]
|
||||
alsa = "^0.1.8"
|
||||
alsa-sys = "^0.1.1"
|
||||
@ -28,6 +25,7 @@ toml = "^0.4.2"
|
||||
which = "*"
|
||||
xdg = "*"
|
||||
libnotify = { path = "3rdparty/libnotify", optional = true }
|
||||
png = "^0.9.0"
|
||||
|
||||
[dependencies.gtk]
|
||||
git = "https://github.com/gtk-rs/gtk.git"
|
||||
|
5
build.rs
5
build.rs
@ -1,5 +0,0 @@
|
||||
extern crate gcc;
|
||||
|
||||
fn main() {
|
||||
gcc::compile_library("libxpm.a", &["src/xpm.c"]);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,6 @@
|
||||
use alsa;
|
||||
use glib;
|
||||
use png;
|
||||
use std::convert::From;
|
||||
use std;
|
||||
use toml;
|
||||
@ -11,6 +12,7 @@ error_chain! {
|
||||
Alsa(alsa::Error);
|
||||
IO(std::io::Error);
|
||||
Toml(toml::de::Error);
|
||||
Png(png::DecodingError);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ extern crate gobject_sys;
|
||||
extern crate gtk;
|
||||
extern crate gtk_sys;
|
||||
extern crate libc;
|
||||
extern crate png;
|
||||
extern crate which;
|
||||
extern crate xdg;
|
||||
|
||||
|
@ -9,7 +9,6 @@ use std::path::*;
|
||||
|
||||
|
||||
|
||||
|
||||
pub fn copy_pixbuf(pixbuf: &gdk_pixbuf::Pixbuf) -> gdk_pixbuf::Pixbuf {
|
||||
|
||||
let new_pixbuf = unsafe {
|
||||
@ -42,49 +41,36 @@ pub fn pixbuf_new_from_theme(icon_name: &str,
|
||||
}
|
||||
|
||||
|
||||
pub fn pixbuf_new_from_file(filename: &str) -> Result<gdk_pixbuf::Pixbuf> {
|
||||
ensure!(!filename.is_empty(), "Filename is empty");
|
||||
let mut syspath = String::new();
|
||||
let sysdir = option_env!("PIXMAPSDIR").map(|s| {
|
||||
syspath = format!("{}/{}",
|
||||
s,
|
||||
filename);
|
||||
Path::new(syspath.as_str())
|
||||
});
|
||||
let cargopath = format!("./data/pixmaps/{}", filename);
|
||||
let cargodir = Path::new(cargopath.as_str());
|
||||
|
||||
// prefer local dir
|
||||
let final_dir = {
|
||||
if cargodir.exists() {
|
||||
cargodir
|
||||
} else if sysdir.is_some() && sysdir.unwrap().exists() {
|
||||
sysdir.unwrap()
|
||||
} else {
|
||||
bail!("No valid path found")
|
||||
}
|
||||
};
|
||||
|
||||
let str_path = final_dir.to_str().ok_or("Path is not valid unicode")?;
|
||||
debug!("Loading icon from {}", str_path);
|
||||
// TODO: propagate error
|
||||
return Ok(gdk_pixbuf::Pixbuf::new_from_file(str_path).unwrap());
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pixbuf_new_from_xpm {
|
||||
($name:ident) => {
|
||||
macro_rules! pixbuf_new_from_file {
|
||||
($name:expr) => {
|
||||
{
|
||||
use glib::translate::from_glib_full;
|
||||
use libc::c_char;
|
||||
extern "C" { fn $name() -> *mut *mut c_char; };
|
||||
use gdk_pixbuf;
|
||||
use png;
|
||||
|
||||
unsafe {
|
||||
from_glib_full(
|
||||
gdk_pixbuf_sys::gdk_pixbuf_new_from_xpm_data($name()))
|
||||
}
|
||||
let bytes = include_bytes!($name);
|
||||
let pixbuf_new_from_bytes = |bytes| -> Result<gdk_pixbuf::Pixbuf> {
|
||||
let decoder = png::Decoder::new(bytes);
|
||||
let (info, mut reader) = decoder.read_info()?;
|
||||
let mut buf = vec![0; info.buffer_size()];
|
||||
reader.next_frame(&mut buf).unwrap();
|
||||
|
||||
ensure!(info.color_type == png::ColorType::RGB ||
|
||||
info.color_type == png::ColorType::RGBA,
|
||||
"Only RGB is supported for GDKPixbuf");
|
||||
|
||||
debug!("Loading icon from {}", $name);
|
||||
|
||||
return Ok(gdk_pixbuf::Pixbuf::new_from_vec(buf,
|
||||
gdk_pixbuf_sys::GDK_COLORSPACE_RGB,
|
||||
true,
|
||||
info.bit_depth as i32,
|
||||
info.width as i32,
|
||||
info.height as i32,
|
||||
info.line_size as i32));
|
||||
};
|
||||
pixbuf_new_from_bytes(bytes as &[u8])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,11 +298,11 @@ impl AudioPix {
|
||||
}
|
||||
} else {
|
||||
AudioPix {
|
||||
muted: pixbuf_new_from_xpm!(pnmixer_muted),
|
||||
low: pixbuf_new_from_xpm!(pnmixer_low),
|
||||
medium: pixbuf_new_from_xpm!(pnmixer_medium),
|
||||
high: pixbuf_new_from_xpm!(pnmixer_high),
|
||||
off: pixbuf_new_from_xpm!(pnmixer_off),
|
||||
muted: pixbuf_new_from_file!("../data/pixmaps/pnmixer-muted.png")?,
|
||||
low: pixbuf_new_from_file!("../data/pixmaps/pnmixer-low.png")?,
|
||||
medium: pixbuf_new_from_file!("../data/pixmaps/pnmixer-medium.png")?,
|
||||
high: pixbuf_new_from_file!("../data/pixmaps/pnmixer-high.png")?,
|
||||
off: pixbuf_new_from_file!("../data/pixmaps/pnmixer-off.png")?,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
32
src/xpm.c
32
src/xpm.c
@ -1,32 +0,0 @@
|
||||
#include "../data/pixmaps/pnmixer-about.xpm"
|
||||
#include "../data/pixmaps/pnmixer-high.xpm"
|
||||
#include "../data/pixmaps/pnmixer-low.xpm"
|
||||
#include "../data/pixmaps/pnmixer-medium.xpm"
|
||||
#include "../data/pixmaps/pnmixer-muted.xpm"
|
||||
#include "../data/pixmaps/pnmixer-off.xpm"
|
||||
|
||||
|
||||
char** pnmixer_about() {
|
||||
return pnmixer_about_xpm;
|
||||
}
|
||||
|
||||
char** pnmixer_high() {
|
||||
return pnmixer_high_xpm;
|
||||
}
|
||||
|
||||
char** pnmixer_low() {
|
||||
return pnmixer_low_xpm;
|
||||
}
|
||||
|
||||
char** pnmixer_medium() {
|
||||
return pnmixer_medium_xpm;
|
||||
}
|
||||
|
||||
char** pnmixer_muted() {
|
||||
return pnmixer_muted_xpm;
|
||||
}
|
||||
|
||||
char** pnmixer_off() {
|
||||
return pnmixer_off_xpm;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user