Skip to content

Commit

Permalink
Delete platform api
Browse files Browse the repository at this point in the history
  • Loading branch information
hlsxx committed Dec 23, 2024
1 parent 0342bc7 commit 48f9b59
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 83 deletions.
18 changes: 0 additions & 18 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ ratatui = "0.29.0"
serde = { version = "1.0.214", features = ["derive"] }
tokio = { version = "1.41.0", features = ["full"] }
toml = "0.8.19"
winapi = "0.3.9"
x11 = "2.21.0"

[dev-dependencies]
uuid = { version = "1.11.0", features = ["v4"] }
Expand Down
3 changes: 0 additions & 3 deletions build.rs

This file was deleted.

94 changes: 47 additions & 47 deletions src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,50 +60,50 @@ impl EventHandler {
}
}

pub struct PlatformApi;

impl PlatformApi {
#[allow(inactive_code)]
#[cfg(target_os = "windows")]
fn is_capslock_on() -> bool {
use winapi::um::winuser::{GetKeyState, VK_CAPITAL};
unsafe { GetKeyState(VK_CAPITAL) & 0x0001 != 0 }
}

#[cfg(target_os = "linux")]
#[allow(unused)]
fn is_capslock_on_wayland() -> bool {
false
}

#[cfg(target_os = "linux")]
fn is_capslock_on_x11() -> bool {
use x11::xlib::{XCloseDisplay, XOpenDisplay, XkbGetIndicatorState};
use std::ptr;

let display = unsafe { XOpenDisplay(ptr::null()) };

if display.is_null() {
eprintln!("Unable to open X display");
return false;
}

let mut state: u32 = 0;
let result = unsafe { XkbGetIndicatorState(display, 0x0100, &mut state) };

unsafe { XCloseDisplay(display) };

result == 0 && state & 0x01 != 0
}

#[cfg(target_os = "linux")]
pub fn is_capslock_on() -> bool {
use std::env;

if env::var("DISPLAY").is_ok() {
return PlatformApi::is_capslock_on_x11();
}

false
}
}
// pub struct PlatformApi;
//
// impl PlatformApi {
// #[allow(inactive_code)]
// #[cfg(target_os = "windows")]
// fn is_capslock_on() -> bool {
// use winapi::um::winuser::{GetKeyState, VK_CAPITAL};
// unsafe { GetKeyState(VK_CAPITAL) & 0x0001 != 0 }
// }
//
// #[cfg(target_os = "linux")]
// #[allow(unused)]
// fn is_capslock_on_wayland() -> bool {
// false
// }
//
// #[cfg(target_os = "linux")]
// fn is_capslock_on_x11() -> bool {
// use x11::xlib::{XCloseDisplay, XOpenDisplay, XkbGetIndicatorState};
// use std::ptr;
//
// let display = unsafe { XOpenDisplay(ptr::null()) };
//
// if display.is_null() {
// eprintln!("Unable to open X display");
// return false;
// }
//
// let mut state: u32 = 0;
// let result = unsafe { XkbGetIndicatorState(display, 0x0100, &mut state) };
//
// unsafe { XCloseDisplay(display) };
//
// result == 0 && state & 0x01 != 0
// }
//
// #[cfg(target_os = "linux")]
// pub fn is_capslock_on() -> bool {
// use std::env;
//
// if env::var("DISPLAY").is_ok() {
// return PlatformApi::is_capslock_on_x11();
// }
//
// false
// }
// }
28 changes: 15 additions & 13 deletions src/screens/typing_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ use ratatui::{
};

use crate::{
config::AppConfig, event_handler::PlatformApi, helper::{get_title, Generator, ToDark}, layout::{Layout as TukaiLayout, LayoutColorTypeEnum}, screens::{Instruction, InstructionWidget, Screen}, storage::{stats::Stat, storage_handler::StorageHandler}
config::AppConfig,
helper::{get_title, Generator, ToDark},
layout::{Layout as TukaiLayout, LayoutColorTypeEnum},
screens::{Instruction, InstructionWidget, Screen},
storage::{stats::Stat, storage_handler::StorageHandler}
};

/// Handler for incorrect symbols
Expand Down Expand Up @@ -360,16 +364,16 @@ impl TypingScreen {
}

/// Returns the CAPSLOCK message line
#[allow(unused)]
fn get_capslock_line(&self, layout: &TukaiLayout) -> Line {
let mut spans = Vec::new();

if PlatformApi::is_capslock_on() {
spans.push(Span::from("❗CAPSLOCK ON").style(Style::default().fg(layout.get_error_color()).bold()));
}

Line::from(spans)
}
// #[allow(unused)]
// fn get_capslock_line(&self, layout: &TukaiLayout) -> Line {
// let mut spans = Vec::new();
//
// if PlatformApi::is_capslock_on() {
// spans.push(Span::from("❗CAPSLOCK ON").style(Style::default().fg(layout.get_error_color()).bold()));
// }
//
// Line::from(spans)
// }

/// Prepare and get a paragraph
pub fn get_paragraph(&self, layout: &TukaiLayout) -> Paragraph {
Expand Down Expand Up @@ -425,8 +429,6 @@ impl TypingScreen {

lines.push(empty_line);

//lines.push(self.get_capslock_line(&layout));

let text = Text::from(lines);

Paragraph::new(text).wrap(Wrap { trim: true } )
Expand Down

0 comments on commit 48f9b59

Please sign in to comment.