Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use clap::{
};
use clap_complete::{Shell, aot::generate as generate_completions};

use crate::surface::{BackgroundImageScale, BackgroundType, FontSlant, FontWeight, Rgba};
use crate::util::{BackgroundImageScale, BackgroundType, FontSlant, FontWeight, Rgba};

#[derive(Copy, Clone, Debug, ValueEnum)]
pub enum LogLevel {
Expand Down
2 changes: 1 addition & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{Result, anyhow};
use atomic_enum::atomic_enum;
use pam_rs::{Client, PamFlag};
use tokio::sync::{mpsc, oneshot};
use tracing::{debug, warn};
use tracing::debug;
use zeroize::Zeroizing;

use crate::config::NLockConfig;
Expand Down
9 changes: 5 additions & 4 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026, Nathan Gill

use nix::{
sys::mman::{MapFlags, ProtFlags, mmap, munmap},
unistd::ftruncate,
};
use std::{
os::{fd::AsFd, raw::c_void},
ptr::NonNull,
Expand All @@ -13,6 +9,11 @@ use std::{
atomic::{AtomicBool, Ordering},
},
};

use nix::{
sys::mman::{MapFlags, ProtFlags, mmap, munmap},
unistd::ftruncate,
};
use wayland_client::{
Dispatch, QueueHandle,
protocol::{wl_buffer, wl_shm, wl_surface},
Expand Down
37 changes: 34 additions & 3 deletions src/cairo_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,53 @@
// Copyright (C) 2026, Nathan Gill

use anyhow::{Result, anyhow};
use cairo::{Context, Format, ImageSurface};
use cairo::{Context, Format, ImageSurface, SubpixelOrder};
use gdk_pixbuf::Pixbuf;
use wayland_client::{WEnum, protocol::wl_output};

use crate::surface::Rgba;
use crate::util::Rgba;

pub trait CairoExt {
fn ext_set_source_rgba(&self, rgba: Rgba);
}

impl CairoExt for Context {
/// Set source RGBA from a `surface::Rgba` structure.
/// Set source RGBA from a `util::Rgba` structure.
fn ext_set_source_rgba(&self, rgba: Rgba) {
self.set_source_rgba(rgba.r, rgba.g, rgba.b, rgba.a);
}
}

pub trait SubpixelOrderExt {
fn from_wl_subpixel(subpixel: WEnum<wl_output::Subpixel>) -> SubpixelOrder;
}

impl SubpixelOrderExt for SubpixelOrder {
/// Convert a Wayland output subpixel enum into a Cairo SubpixelOrder
///
/// If the specified output subpixel order has no Cairo equivalent,
/// the Cairo default will be used.
fn from_wl_subpixel(subpixel: WEnum<wl_output::Subpixel>) -> SubpixelOrder {
match subpixel {
WEnum::Value(wl_output::Subpixel::HorizontalRgb) => {
return SubpixelOrder::Rgb;
}
WEnum::Value(wl_output::Subpixel::HorizontalBgr) => {
return SubpixelOrder::Bgr;
}
WEnum::Value(wl_output::Subpixel::VerticalRgb) => {
return SubpixelOrder::Vrgb;
}
WEnum::Value(wl_output::Subpixel::VerticalBgr) => {
return SubpixelOrder::Vbgr;
}
_ => {
return SubpixelOrder::Default;
}
}
}
}

pub trait ImageSurfaceExt {
fn create_from_pixbuf(pixbuf: &Pixbuf) -> Result<ImageSurface>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::debug;

use crate::{
args::NLockArgs,
surface::{BackgroundImageScale, BackgroundType, FontSlant, FontWeight, Rgba},
util::{BackgroundImageScale, BackgroundType, FontSlant, FontWeight, Rgba},
};

const CONFIG_FILE_NAME: &str = "nlock.toml";
Expand Down
9 changes: 5 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026, Nathan Gill

use std::{
os::fd::{AsFd, AsRawFd, BorrowedFd},
sync::atomic::Ordering,
};

use anyhow::{Result, anyhow};
use mio::{Events, Interest, Poll, Token, unix::SourceFd};
use nix::{
sys::timerfd::{ClockId, Expiration, TimerFd, TimerFlags, TimerSetTimeFlags},
unistd::read,
};
use std::{
os::fd::{AsFd, AsRawFd, BorrowedFd},
sync::atomic::Ordering,
};
use wayland_client::{EventQueue, QueueHandle, backend::ReadEventsGuard};

use crate::{state::NLockState, util::is_eintr};
Expand Down
17 changes: 9 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@
pub mod args;
pub mod auth;
pub mod buffer;
pub mod cairo_ext;
pub mod config;
pub mod event;
pub mod cairo_ext;
pub mod render;
pub mod seat;
pub mod state;
pub mod surface;
pub mod util;

use std::sync::atomic::Ordering;

use crate::{
args::run_cli,
auth::{AuthConfig, AuthRequest, run_auth_loop},
config::NLockConfig,
state::NLockState,
};

use anyhow::{Result, bail};

#[cfg_attr(debug_assertions, allow(unused_imports))]
Expand All @@ -30,6 +24,13 @@ use tokio::sync::mpsc;
use tracing::{debug, error, warn};
use wayland_client::Connection;

use crate::{
args::run_cli,
auth::{AuthConfig, AuthRequest, run_auth_loop},
config::NLockConfig,
state::NLockState,
};

async fn start(config: NLockConfig) -> Result<()> {
// Prevent ptrace from attaching to nlock
// Only do this in release config
Expand Down
Loading