Skip to content

Commit

Permalink
Fix all warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
H-M-H committed May 2, 2020
1 parent 76f7e20 commit 3b58c0c
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ jobs:
package-files: |
target/release/linux.zip
target/debian/Weylus*.deb
pkg-cmd: cd target/release/ && zip linux.zip Weylus
pkg-cmd: cd target/release/ && zip linux.zip weylus
- os: macOS-latest
build-cmd: npm install -g typescript && cargo install cargo-bundle && cargo bundle --release
package-files: target/release/bundle/osx/macOS.zip
pkg-cmd: cd target/release/bundle/osx/ && zip -r macOS.zip Weylus.app
- os: windows-latest
build-cmd: npm install -g typescript && npm run build && cargo build --release --verbose
package-files: target/release/Windows.zip
pkg-cmd: cd target/release/ && 7z a Windows.zip Weylus.exe
pkg-cmd: cd target/release/ && 7z a Windows.zip weylus.exe

steps:
- name: Download deps
Expand Down
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "Weylus"
name = "weylus"
version = "0.1.0"
authors = ["HMH <[email protected]>"]
edition = "2018"
Expand Down Expand Up @@ -36,9 +36,7 @@ name = "Weylus"
identifier = "io.github.h-m-h.weylus"

[package.metadata.deb]
name = "Weylus"
depends = "$auto"
section = "utility"
priority = "optional"
assets = [
["target/release/Weylus", "usr/bin/weylus", "755"],
]
2 changes: 2 additions & 0 deletions compile_flags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
-lX11
-lXext
-Wall
-Wextra
10 changes: 6 additions & 4 deletions lib/linux/capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ typedef struct CaptureContext CaptureContext;
struct Image
{
char* data;
int width;
int height;
unsigned int width;
unsigned int height;
};

void* init_capture(WindowInfo* winfo, CaptureContext* ctx, Error* err)
Expand Down Expand Up @@ -89,7 +89,9 @@ void destroy_capture(CaptureContext* ctx, Error* err)
{
XShmDetach(ctx->winfo.disp, &ctx->shminfo);
XDestroyImage(ctx->ximg);
shmdt(ctx->shminfo.shmaddr);
if (shmdt(ctx->shminfo.shmaddr) != 0) {
fill_error(err, 1, "Failed to detach shared memory!");
}
free(ctx);
}

Expand All @@ -105,7 +107,7 @@ void capture_sceen(CaptureContext* ctx, struct Image* img, Error* err)
ERROR(err, 1, "Failed to get window geometry!");
}
// if window resized, create new capture...
if (width != ctx->ximg->width || height != ctx->ximg->height)
if (width != (unsigned int)ctx->ximg->width || height != (unsigned int)ctx->ximg->height)
{
XShmDetach(ctx->winfo.disp, &ctx->shminfo);
XDestroyImage(ctx->ximg);
Expand Down
3 changes: 1 addition & 2 deletions lib/linux/uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void setup(int fd, const char* name, int product, Error* err)

struct uinput_setup setup;
memset(&setup, 0, sizeof(setup));
strncpy(setup.name, name, UINPUT_MAX_NAME_SIZE);
strncpy(setup.name, name, UINPUT_MAX_NAME_SIZE - 1);
setup.id.bustype = BUS_VIRTUAL;
setup.id.vendor = 0x1;
setup.id.product = product;
Expand Down Expand Up @@ -114,7 +114,6 @@ void init_multitouch(int fd, Error* err)
if (ioctl(fd, UI_SET_KEYBIT, BTN_TOOL_QUINTTAP) < 0)
ERROR(err, 1, "error: ioctl UI_SET_KEYBIT");


if (ioctl(fd, UI_SET_EVBIT, EV_ABS) < 0)
ERROR(err, 1, "error: ioctl UI_SET_EVBIT EV_ABS");

Expand Down
29 changes: 10 additions & 19 deletions lib/linux/xwindows.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
int locale_to_utf8(char* src, char* dest, size_t size)
{
iconv_t icd = iconv_open("UTF-8//IGNORE", "");
size_t src_size = strlen(src);
size_t inbytes = src_size;
size_t src_size = size;
size_t outbytes_left = MAX_PROPERTY_VALUE_LEN - 1;
int ret = iconv(icd, &src, &src_size, &dest, &outbytes_left);
iconv_close(icd);
Expand Down Expand Up @@ -160,7 +159,6 @@ size_t get_window_info(Display* disp, WindowInfo* windows, size_t size, Error* e
{
Window* client_list;
unsigned long client_list_size;
int max_client_machine_len = 0;

if ((client_list = get_client_list(disp, &client_list_size, err)) == NULL)
{
Expand All @@ -170,13 +168,13 @@ size_t get_window_info(Display* disp, WindowInfo* windows, size_t size, Error* e
size_t num_windows = client_list_size / sizeof(Window);

/* print the list */
for (int i = 0; i < num_windows && i < size; i++)
for (size_t i = 0; i < num_windows && i < size; i++)
{
char* title_utf8 = get_window_title(disp, client_list[i], NULL);
if (title_utf8 == NULL)
{
title_utf8 = malloc(16);
snprintf(title_utf8, 16, "UNKNOWN %d", i);
title_utf8 = malloc(32);
snprintf(title_utf8, 32, "UNKNOWN %lu", i);
}
unsigned long* desktop;

Expand All @@ -192,7 +190,7 @@ size_t get_window_info(Display* disp, WindowInfo* windows, size_t size, Error* e
windows[i].win = client_list[i];
// special desktop ID -1 means "all desktops"
// use -2 to indicate that no desktop has been found
windows[i].desktop_id = desktop ? *desktop : -2;
windows[i].desktop_id = desktop ? (signed long)*desktop : -2;
strncpy(windows[i].title, title_utf8, sizeof(windows->title));
free(title_utf8);
free(desktop);
Expand All @@ -219,8 +217,6 @@ void get_window_geometry_relative(
WindowInfo* winfo, float* x, float* y, float* width, float* height, Error* err)
{
Window junkroot;
int junkx, junky;
unsigned int bw, depth;
int x_tmp, y_tmp;

XWindowAttributes window_attributes;
Expand All @@ -232,8 +228,8 @@ void get_window_geometry_relative(
winfo->disp,
winfo->win,
window_attributes.root,
junkx,
junky,
window_attributes.x,
window_attributes.y,
&x_tmp,
&y_tmp,
&junkroot))
Expand All @@ -247,15 +243,11 @@ void get_window_geometry_relative(
*height = window_attributes.height / (float)window_attributes.screen->height;
}

void get_root_window_info(Display* disp, WindowInfo* winfo, Error* err)
void get_root_window_info(Display* disp, WindowInfo* winfo)
{
Window root = DefaultRootWindow(disp);
char* title_utf8 = get_window_title(disp, root, NULL);
if (title_utf8 == NULL)
{
title_utf8 = malloc(13);
snprintf(title_utf8, 13, "UNKNOWN Root");
}
char* title_utf8 = malloc(12);
snprintf(title_utf8, 12, "Root Window");
winfo->disp = disp;
strncpy(winfo->title, title_utf8, sizeof(winfo->title));
winfo->win = root;
Expand Down Expand Up @@ -325,7 +317,6 @@ void activate_window(WindowInfo* winfo, Error* err)
ERROR(err, 1, "Cannot find desktop ID of the window.");
}
}
XEvent event;
client_msg(winfo->disp, DefaultRootWindow(winfo->disp), "_NET_CURRENT_DESKTOP", *desktop, 0, 0, 0, 0, err);
free(desktop);
OK_OR_ABORT(err);
Expand Down
5 changes: 3 additions & 2 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub fn run() {
.below_of(&check_faster_screencapture, padding)
.with_label("Capturing windows is\nonly supported on Linux!");

#[allow(unused_mut)]
let mut choice_window = Choice::default()
.with_size(width, height)
.below_of(&label_window_choice, 0);
Expand Down Expand Up @@ -210,7 +211,7 @@ pub fn run() {
#[cfg(target_os = "linux")]
let mut x11_context = X11Context::new().unwrap();
#[cfg(target_os = "linux")]
let capture_window = Rc::new(RefCell::new(x11_context.root_window().unwrap()));
let capture_window = Rc::new(RefCell::new(x11_context.root_window()));

#[cfg(target_os = "linux")]
{
Expand All @@ -222,7 +223,7 @@ pub fn run() {
let mut choice_window = choice_window_ref.borrow_mut();
choice_window.clear();
{
let root_window = x11_context.root_window().unwrap();
let root_window = x11_context.root_window();
let capture_window = capture_window.clone();
choice_window.add(
"",
Expand Down
52 changes: 26 additions & 26 deletions src/input/uinput_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ use crate::x11helper::WindowInfo;

use crate::cerror::CError;

use tracing::{info, warn};
use tracing::warn;

extern "C" {
fn init_uinput_pointer(err: *mut CError) -> c_int;
fn init_uinput_multitouch(err: *mut CError) -> c_int;
// fn init_uinput_multitouch(err: *mut CError) -> c_int;
fn destroy_uinput_device(fd: c_int);
fn send_uinput_event(device: c_int, typ: c_int, code: c_int, value: c_int, err: *mut CError);
}

struct MultiTouch {
/*struct MultiTouch {
id: i64,
}
}*/

pub struct GraphicTablet {
pointer_fd: c_int,
multitouch_fd: c_int,
multi_touches: [Option<MultiTouch>; 5],
// multitouch_fd: c_int,
// multi_touches: [Option<MultiTouch>; 5],
winfo: WindowInfo,
x: f64,
y: f64,
Expand All @@ -45,8 +45,8 @@ impl GraphicTablet {
}*/
let tblt = Self {
pointer_fd: pointer_fd,
multitouch_fd: 0, // multitouch_fd,
multi_touches: Default::default(),
// multitouch_fd: 0, // multitouch_fd,
// multi_touches: Default::default(),
winfo: winfo,
x: 0.0,
y: 0.0,
Expand All @@ -70,7 +70,7 @@ impl GraphicTablet {
(p * 65535.0) as i32
}

fn transform_touch_size(&self, s: f64) -> i32 {
/*fn transform_touch_size(&self, s: f64) -> i32 {
(s * 65535.0) as i32
}
Expand All @@ -88,7 +88,7 @@ impl GraphicTablet {
}
_ => None,
})
}
}*/

fn send(&self, typ: c_int, code: c_int, value: c_int) {
let mut err = CError::new();
Expand All @@ -100,15 +100,15 @@ impl GraphicTablet {
}
}

fn send_touch(&self, typ: c_int, code: c_int, value: c_int) {
/*fn send_touch(&self, typ: c_int, code: c_int, value: c_int) {
let mut err = CError::new();
unsafe {
send_uinput_event(self.multitouch_fd, typ, code, value, &mut err);
}
if err.is_err() {
warn!("{}", err);
}
}
}*/
}

impl Drop for GraphicTablet {
Expand All @@ -123,32 +123,32 @@ impl Drop for GraphicTablet {
// Event Types
const ET_SYNC: c_int = 0x00;
const ET_KEY: c_int = 0x01;
const ET_RELATIVE: c_int = 0x02;
//const ET_RELATIVE: c_int = 0x02;
const ET_ABSOLUTE: c_int = 0x03;

// Event Codes
const EC_SYNC_REPORT: c_int = 1;
const EC_SYNC_MT_REPORT: c_int = 2;
//const EC_SYNC_MT_REPORT: c_int = 2;

const EC_KEY_MOUSE_LEFT: c_int = 0x110;
const EC_KEY_TOOL_PEN: c_int = 0x140;
const EC_KEY_TOUCH: c_int = 0x14a;
const EC_KEY_STYLUS: c_int = 0x14b;
const EC_KEY_TOOL_FINGER: c_int = 0x145;
const EC_KEY_TOOL_DOUBLETAP: c_int = 0x14d;
const EC_KEY_TOOL_TRIPLETAP: c_int = 0x14e;
const EC_KEY_TOOL_QUADTAP: c_int = 0x14f; /* Four fingers on trackpad */
const EC_KEY_TOOL_QUINTTAP: c_int = 0x148; /* Five fingers on trackpad */
//const EC_KEY_TOUCH: c_int = 0x14a;
//const EC_KEY_STYLUS: c_int = 0x14b;
//const EC_KEY_TOOL_FINGER: c_int = 0x145;
//const EC_KEY_TOOL_DOUBLETAP: c_int = 0x14d;
//const EC_KEY_TOOL_TRIPLETAP: c_int = 0x14e;
//const EC_KEY_TOOL_QUADTAP: c_int = 0x14f; /* Four fingers on trackpad */
//const EC_KEY_TOOL_QUINTTAP: c_int = 0x148; /* Five fingers on trackpad */

const EC_RELATIVE_X: c_int = 0x00;
const EC_RELATIVE_Y: c_int = 0x01;
//const EC_RELATIVE_X: c_int = 0x00;
//const EC_RELATIVE_Y: c_int = 0x01;

const EC_ABSOLUTE_X: c_int = 0x00;
const EC_ABSOLUTE_Y: c_int = 0x01;
const EC_ABSOLUTE_PRESSURE: c_int = 0x18;
const EC_ABSOLUTE_TILT_X: c_int = 0x1a;
const EC_ABSOLUTE_TILT_Y: c_int = 0x1b;
const EC_ABS_MT_SLOT: c_int = 0x2f; /* MT slot being modified */
/*const EC_ABS_MT_SLOT: c_int = 0x2f; /* MT slot being modified */
const EC_ABS_MT_TOUCH_MAJOR: c_int = 0x30; /* Major axis of touching ellipse */
const EC_ABS_MT_TOUCH_MINOR: c_int = 0x31; /* Minor axis (omit if circular) */
const EC_ABS_MT_ORIENTATION: c_int = 0x34; /* Ellipse orientation */
Expand All @@ -158,7 +158,7 @@ const EC_ABS_MT_TRACKING_ID: c_int = 0x39; /* Unique ID of initiated contact */
const EC_ABS_MT_PRESSURE: c_int = 0x3a; /* Pressure on contact area */
// Maximum for Absolute Values
const ABS_MAX: c_int = 65535;
const ABS_MAX: c_int = 65535;*/

impl PointerDevice for GraphicTablet {
fn send_event(&mut self, event: &PointerEvent) {
Expand Down Expand Up @@ -290,7 +290,7 @@ impl PointerDevice for GraphicTablet {
self.send(
ET_ABSOLUTE,
EC_ABSOLUTE_PRESSURE,
self.transform_pressure(1.0),
self.transform_pressure(0.5),
);
match event.event_type {
PointerEventType::DOWN => self.send(ET_KEY, EC_KEY_MOUSE_LEFT, 1),
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ mod websocket;
mod x11helper;

fn main() {
let subscriber = tracing_subscriber::fmt()
#[cfg(debug_assertions)]
let _subscriber = tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();
#[cfg(not(debug_assertions))]
let _subscriber = tracing_subscriber::fmt()
.with_max_level(Level::WARN)
.init();
gui::run();
}
Loading

0 comments on commit 3b58c0c

Please sign in to comment.