Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: respect system-configured interface font #182

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/target/
/vendor.tar
/vendor/
result*
1 change: 1 addition & 0 deletions daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct UserData {
pub full_name_opt: Option<String>,
pub icon_opt: Option<Vec<u8>>,
pub theme_opt: Option<Theme>,
pub interface_font_opt: Option<String>,
pub wallpapers_opt: Option<Vec<(String, WallpaperData)>>,
pub xkb_config_opt: Option<XkbConfig>,
pub clock_military_time: bool,
Expand Down
10 changes: 10 additions & 0 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl GreeterProxy {
.map(|gecos| gecos.split(',').next().unwrap_or_default().to_string()),
icon_opt,
theme_opt: None,
interface_font_opt: None,
//TODO: should wallpapers come from a per-user call?
wallpapers_opt: None,
xkb_config_opt: None,
Expand Down Expand Up @@ -226,6 +227,15 @@ impl GreeterProxy {
);
}
};

match cosmic_config::Config::new("com.system76.CosmicTk", 1) {
Ok(config_handler) => {
user_data.interface_font_opt = config_handler.get("interface_font").unwrap_or_default();
}
Err(err) => {
log::error!("failed to create CosmicTk config handler: {:?}", err);
}
};
})
.map_err(|err| GreeterError::RunAsUser(err.to_string()))?;

Expand Down
58 changes: 58 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};

outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-linux"
"x86_64-linux"
];

perSystem =
{ pkgs, self', ... }:
{
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
cargo
clippy
rustc
rustfmt
];

strictDeps = true;
};
packages = {
default = self'.packages.cosmic-greeter;
cosmic-greeter = pkgs.callPackage ./package.nix { };
};
};
};
}
113 changes: 113 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Based on lilyinstarlight's work on:
# https://github.com/lilyinstarlight/nixos-cosmic/blob/main/pkgs/cosmic-greeter/package.nix
{
lib,
rustPlatform,
cmake,
coreutils,
just,
libinput,
linux-pam,
stdenv,
udev,
xkeyboard_config,
wayland,
vulkan-loader,
xorg,
libGL,
libxkbcommon,
makeBinaryWrapper,
pkg-config,
cosmic-icons,
}:
rustPlatform.buildRustPackage {
pname = "cosmic-greeter";
version = "1.0.0-alpha.5.1";

src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.difference ./. (
lib.fileset.unions [
(lib.fileset.maybeMissing ./result)
(lib.fileset.maybeMissing ./target)
(lib.fileset.maybeMissing ./.git)
(lib.fileset.fileFilter (
file:
builtins.elem file.name [
"flake.nix"
"flake.lock"
"LICENSE"
"README.md"
".gitignore"
".gitattributes"
"package.nix"
]
) ./.)
]
);
};

nativeBuildInputs = [
cmake
just
makeBinaryWrapper
pkg-config
rustPlatform.bindgenHook
];

buildInputs = [
libinput
linux-pam
udev
wayland
vulkan-loader
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libxcb
libGL
libxkbcommon
];

useFetchCargoVendor = true;
cargoHash = "sha256-nmkM/Jm2P5ftZFfzX+O1Fe6eobRbgBkajZsbyI67Zfw=";
cargoBuildFlags = [ "--all" ];

dontUseJustBuild = true;
dontUseJustCheck = true;

justFlags = [
"--set"
"prefix"
(placeholder "out")
"--set"
"bin-src"
"target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cosmic-greeter"
"--set"
"daemon-src"
"target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cosmic-greeter-daemon"
];

postPatch = ''
substituteInPlace src/greeter.rs --replace-fail '/usr/bin/env' '${lib.getExe' coreutils "env"}'
'';

postInstall = ''
wrapProgram "$out/bin/cosmic-greeter" \
--set-default X11_BASE_RULES_XML "${xkeyboard_config}/share/X11/xkb/rules/base.xml" \
--set-default X11_EXTRA_RULES_XML "${xkeyboard_config}/share/X11/xkb/rules/base.extras.xml" \
--suffix XDG_DATA_DIRS : "${cosmic-icons}/share" \
--prefix LD_LIBRARY_PATH : "${
lib.makeLibraryPath [
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libxcb
libGL
libxkbcommon
wayland
vulkan-loader
]
}"
'';
}
35 changes: 35 additions & 0 deletions src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fn user_data_fallback() -> Vec<UserData> {
.map(|gecos| gecos.split(',').next().unwrap_or_default().to_string()),
icon_opt,
theme_opt: None,
interface_font_opt: None,
wallpapers_opt: None,
xkb_config_opt: None,
clock_military_time: false,
Expand Down Expand Up @@ -299,6 +300,14 @@ pub fn main() -> Result<(), Box<dyn Error>> {
}
};

let tk_config_handler = match cosmic_config::Config::new("com.system76.CosmicTk", 1) {
Ok(config_handler) => Some(config_handler),
Err(err) => {
log::error!("failed to create cosmic-tk config handler: {}", err);
None
}
};

let fallback_background =
widget::image::Handle::from_memory(include_bytes!("../res/background.jpg"));

Expand All @@ -307,6 +316,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
sessions,
layouts_opt,
comp_config_handler,
tk_config_handler,
greeter_config,
greeter_config_handler,
fallback_background,
Expand All @@ -325,6 +335,7 @@ pub struct Flags {
sessions: HashMap<String, (Vec<String>, Vec<String>)>,
layouts_opt: Option<Arc<xkb_data::KeyboardLayouts>>,
comp_config_handler: Option<cosmic_config::Config>,
tk_config_handler: Option<cosmic_config::Config>,
greeter_config: CosmicGreeterConfig,
greeter_config_handler: Option<cosmic_config::Config>,
fallback_background: widget::image::Handle,
Expand Down Expand Up @@ -480,6 +491,26 @@ impl App {
}
}

fn set_interface_font(&self) {
let user_data = match self
.selected_username
.data_idx
.and_then(|i| self.flags.user_datas.get(i))
{
Some(some) => some,
None => return,
};

if let Some(tk_config_handler) = &self.flags.tk_config_handler {
if let Some(font) = &user_data.interface_font_opt {
match tk_config_handler.set("interface_font", font) {
Ok(()) => log::info!("updated cosmic-tk interface_font"),
Err(err) => log::error!("failed to update cosmic-tk interface_font: {}", err),
}
}
}
}

fn update_user_config(&mut self) -> Command<Message> {
let user_data = match self
.selected_username
Expand Down Expand Up @@ -573,6 +604,10 @@ impl App {
}
}

if let Some(font) = &user_data.interface_font_opt {
self.set_interface_font();
}

match &user_data.theme_opt {
Some(theme) => {
cosmic::app::command::set_theme(cosmic::Theme::custom(Arc::new(theme.clone())))
Expand Down