Skip to content

Commit

Permalink
Merge pull request #204 from pop-os/gtk-rs-0.17
Browse files Browse the repository at this point in the history
chore: Update gtk-rs crates to 0.17
  • Loading branch information
ids1024 authored Jul 13, 2023
2 parents deb8384 + 926633e commit aabc184
Show file tree
Hide file tree
Showing 24 changed files with 455 additions and 427 deletions.
342 changes: 220 additions & 122 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ members = [ "tools", "ffi", "backend", "widgets" ]
[dependencies]
cascade = "1"
futures = "0.3.13"
gtk = { version = "0.15.0", features = ["v3_22"] }
gtk = { version = "0.17.0" }
libc = "0.2"
once_cell = "1.4"
pangocairo = "0.15.0"
pangocairo = "0.17.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
log = "0.4.0"
Expand All @@ -28,7 +28,7 @@ i18n-embed-fl = "0.5.0"
rust-embed = { version = "5.9.0", features = ["debug-embed"] }

[build-dependencies]
gio = "0.15.0"
glib-build-tools = "0.17.0"

[target.'cfg(target_os = "windows")'.dependencies]
winreg = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async-process = "1.7.0"
cascade = "1"
futures = { version = "0.3.13", features = ["thread-pool"] }
futures-timer = "3.0.2"
glib = { version = "0.15.0", optional = true }
glib = { version = "0.17.0", optional = true }
hidapi = { version = "1.2", default-features = false, features = ["linux-shared-hidraw"] }
libc = "0.2"
once_cell = "1.4"
Expand Down
8 changes: 6 additions & 2 deletions backend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ fn main() {
.unwrap_or_else(|| {
panic!("'keyboard:' not found in {}", path.display());
});
let is_qmk = meta
.get("is_qmk")
.and_then(|v| v.as_bool())
.unwrap_or(false);

writeln!(
outfile,
" (\"system76/{}\", \"{}\"),",
file_name, keyboard
" (\"system76/{}\", \"{}\", {}),",
file_name, keyboard, is_qmk
)
.unwrap();

Expand Down
2 changes: 2 additions & 0 deletions backend/src/layout/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ pub struct Meta {
#[serde(default = "num_layers_default")]
pub num_layers: u8,
pub pressed_color: Rgb,
#[serde(default)]
pub is_qmk: bool,
}
2 changes: 1 addition & 1 deletion backend/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Layout {
}

macro_rules! keyboards {
($( ($board:expr, $keyboard:expr) ),* $(,)?) => {
($( ($board:expr, $keyboard:expr, $is_qmk:expr) ),* $(,)?) => {
fn layout_data(board: &str, use_legacy_scancodes: bool) -> Option<(&'static str, &'static str, &'static str, &'static str, &'static str, &'static str)> {
match board {
$(
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
gio::compile_resources(
"data",
glib_build_tools::compile_resources(
&["data"],
"data/com.system76.keyboardconfigurator.gresource.xml",
"compiled.gresource",
);
Expand Down
2 changes: 1 addition & 1 deletion ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ name = "system76_keyboard_configurator"
crate-type = [ "cdylib" ]

[dependencies]
gtk = "0.15.0"
gtk = "0.17.0"
system76-keyboard-configurator-widgets = { path = "../widgets" }
7 changes: 7 additions & 0 deletions layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,14 @@ def generate_layout_dir(ecdir: str, board: str, is_qmk: bool, override: str) ->
parser.add_argument("ecdir", help='For QMK boards that is the qmk_firmware (github.com/system76/qmk_firmware) directory itself, otherwise use the ec directory (github.com/system76/ec)')
parser.add_argument("board", help='The name of the manufacturer and board name. Example: "system76/launch_2"')
parser.add_argument("--qmk", action="store_true", help="Required if you plan on using a keyboard with QMK firmware.")
parser.add_argument("--qmk-legacy", action="store_true", help="Re-generate keymap json for old qmk version.")
parser.add_argument("--override", help="Override the output directory. See layouts/keyboards/. Usage: '--override overrides/0.19.12/'", default='')
args = parser.parse_args()

if args.qmk_legacy:
# Only keymap differs for legacy qmk, so don't generate anything related to individial boards
sys.exit(0)

if args.board == 'all':
if args.qmk:
boarddir = f'{args.ecdir}/keyboards/system76'
Expand All @@ -570,3 +575,5 @@ def generate_layout_dir(ecdir: str, board: str, is_qmk: bool, override: str) ->
generate_layout_dir(args.ecdir, f'system76/{i}', args.qmk, args.override)
else:
generate_layout_dir(args.ecdir, args.board, args.qmk, args.override)


62 changes: 22 additions & 40 deletions src/backlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ impl ObjectSubclass for BacklightInner {
}

impl ObjectImpl for BacklightInner {
fn constructed(&self, obj: &Self::Type) {
fn constructed(&self) {
let obj = self.obj();

self.do_not_set.set(true);

let mode_combobox = cascade! {
Expand Down Expand Up @@ -80,11 +82,11 @@ impl ObjectImpl for BacklightInner {
let saturation_adjustment = cascade! {
gtk::Adjustment::new(0., 0., 100., 1., 1., 0.);
..bind_property("value", &keyboard_color, "hs")
.transform_from(|_, value| {
.transform_from(|_, value: glib::Value| {
let hs: &Hs = value.get().unwrap();
Some((hs.s * 100.).to_value())
})
.transform_to(|_, value| {
.transform_to(|_, value: glib::Value| {
let s: f64 = value.get().unwrap();
Some(Hs::new(0., s / 100.).to_value())
})
Expand Down Expand Up @@ -171,61 +173,41 @@ impl ObjectImpl for BacklightInner {
self.saturation_row.set(saturation_row);
}

fn dispose(&self, obj: &Self::Type) {
obj.led_save();
fn dispose(&self) {
self.obj().led_save();
}

fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![
glib::ParamSpecString::new(
"mode",
"mode",
"mode",
None,
glib::ParamFlags::READABLE,
),
glib::ParamSpecBoxed::new(
"selected",
"selected",
"selected",
SelectedKeys::static_type(),
glib::ParamFlags::WRITABLE,
),
glib::ParamSpecBoolean::new(
"is-per-key",
"is-per-key",
"is-per-key",
false,
glib::ParamFlags::READABLE,
),
glib::ParamSpecString::builder("mode").read_only().build(),
glib::ParamSpecBoxed::builder::<SelectedKeys>("selected")
.write_only()
.build(),
glib::ParamSpecBoolean::builder("is-per-key")
.read_only()
.build(),
]
});

PROPERTIES.as_ref()
}

fn set_property(
&self,
obj: &Self::Type,
_id: usize,
value: &glib::Value,
pspec: &glib::ParamSpec,
) {
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
match pspec.name() {
"selected" => {
let selected: &SelectedKeys = value.get().unwrap();
obj.inner().selected.replace(selected.clone());
obj.update_per_key();
self.selected.replace(selected.clone());
self.obj().update_per_key();
}
_ => unimplemented!(),
}
}

fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
match pspec.name() {
"mode" => obj.mode().id.to_value(),
"is-per-key" => obj.mode().is_per_key().to_value(),
"mode" => self.obj().mode().id.to_value(),
"is-per-key" => self.obj().mode().is_per_key().to_value(),
_ => unimplemented!(),
}
}
Expand All @@ -245,7 +227,7 @@ impl Backlight {
let max_brightness = board.max_brightness() as f64;
let has_led_save = board.has_led_save();

let obj: Self = glib::Object::new(&[]).unwrap();
let obj: Self = glib::Object::new();
obj.inner().board.set(board.clone());
obj.inner().keyboard_color.set_board(Some(board));
obj.inner().brightness_scale.set_range(0.0, max_brightness);
Expand Down Expand Up @@ -280,7 +262,7 @@ impl Backlight {
}

fn inner(&self) -> &BacklightInner {
BacklightInner::from_instance(self)
BacklightInner::from_obj(self)
}

fn board(&self) -> &Board {
Expand Down
29 changes: 16 additions & 13 deletions src/configurator_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ impl ObjectSubclass for ConfiguratorAppInner {
}

impl ObjectImpl for ConfiguratorAppInner {
fn constructed(&self, app: &ConfiguratorApp) {
fn constructed(&self) {
let app = self.obj();

app.set_application_id(Some("com.system76.keyboardconfigurator"));

self.parent_constructed(app);
self.parent_constructed();

app.add_main_option(
"fake-keyboard",
Expand Down Expand Up @@ -54,7 +56,7 @@ impl ObjectImpl for ConfiguratorAppInner {
}

impl ApplicationImpl for ConfiguratorAppInner {
fn handle_local_options(&self, _app: &ConfiguratorApp, opts: &glib::VariantDict) -> i32 {
fn handle_local_options(&self, opts: &glib::VariantDict) -> glib::ExitCode {
fn lookup<T: glib::FromVariant>(opts: &glib::VariantDict, key: &str) -> Option<T> {
opts.lookup_value(key, None)?.get()
}
Expand All @@ -69,11 +71,11 @@ impl ApplicationImpl for ConfiguratorAppInner {
self.debug_layers.set(opts.contains("debug-layers"));
self.launch_test.set(opts.contains("launch-test"));

-1
self.parent_handle_local_options(opts)
}

fn startup(&self, app: &ConfiguratorApp) {
self.parent_startup(app);
fn startup(&self) {
self.parent_startup();

let about_action = cascade! {
gio::SimpleAction::new("about", None);
Expand Down Expand Up @@ -110,6 +112,7 @@ impl ApplicationImpl for ConfiguratorAppInner {
});
};

let app = self.obj();
app.add_action(&about_action);
app.add_action(&flash_heavy_1);
app.add_action(&flash_2);
Expand All @@ -122,14 +125,14 @@ impl ApplicationImpl for ConfiguratorAppInner {
}
}

fn activate(&self, app: &ConfiguratorApp) {
self.parent_activate(app);
fn activate(&self) {
self.parent_activate();

if let Some(window) = app.active_window() {
if let Some(window) = self.obj().active_window() {
info!("Focusing current window");
window.present();
} else {
MainWindow::new(app);
MainWindow::new(&*self.obj());
}
}
}
Expand All @@ -144,11 +147,11 @@ glib::wrapper! {

impl ConfiguratorApp {
fn new() -> Self {
glib::Object::new(&[]).unwrap()
glib::Object::new()
}

fn inner(&self) -> &ConfiguratorAppInner {
ConfiguratorAppInner::from_instance(self)
ConfiguratorAppInner::from_obj(self)
}

pub fn phony_board_names(&self) -> &[String] {
Expand Down Expand Up @@ -225,7 +228,7 @@ fn windows_init() {
}
}

pub fn run() -> i32 {
pub fn run() -> glib::ExitCode {
gtk::init().unwrap();

glib::set_prgname(Some("com.system76.keyboardconfigurator"));
Expand Down
Loading

0 comments on commit aabc184

Please sign in to comment.