forked from vitrine/wmaker
First stab at defining WApplication methods in Rust.
This builds and appears to run.
This commit is contained in:
@@ -6,7 +6,13 @@ bin_PROGRAMS = wmaker
|
||||
|
||||
EXTRA_DIST =
|
||||
|
||||
wmakerlib = $(top_builddir)/wmakerlib/target/debug/libwmakerlib.a
|
||||
|
||||
$(wmakerlib):
|
||||
@(cd $(top_builddir)/wmakerlib && cargo build)
|
||||
|
||||
wmaker_SOURCES = \
|
||||
$(wmakerlib) \
|
||||
GNUstep.h \
|
||||
WindowMaker.h \
|
||||
actions.c \
|
||||
@@ -135,7 +141,7 @@ else
|
||||
nodist_wmaker_SOURCES = misc.hack_nf.c \
|
||||
xmodifier.hack_nf.c
|
||||
|
||||
CLEANFILES = $(nodist_wmaker_SOURCES)
|
||||
CLEANFILES = $(nodist_wmaker_SOURCES) ../wmakerlib/target
|
||||
|
||||
misc.hack_nf.c: misc.c $(top_srcdir)/script/nested-func-to-macro.sh
|
||||
$(AM_V_GEN)$(top_srcdir)/script/nested-func-to-macro.sh \
|
||||
@@ -161,6 +167,7 @@ wmaker_LDADD = \
|
||||
$(top_builddir)/WINGs/libWINGs.la\
|
||||
$(top_builddir)/WINGs/libWUtil.la\
|
||||
$(top_builddir)/wrlib/libwraster.la\
|
||||
$(wmakerlib)\
|
||||
@XLFLAGS@ \
|
||||
@LIBXRANDR@ \
|
||||
@LIBXINERAMA@ \
|
||||
|
||||
@@ -59,87 +59,13 @@ struct WApplication {
|
||||
};
|
||||
|
||||
/******** Accessors/mutators ********/
|
||||
Window wApplicationGetMainWindow(WApplication *wapp) {
|
||||
return wapp->main_window;
|
||||
}
|
||||
|
||||
WMenu *wApplicationGetMenu(WApplication *wapp) {
|
||||
return wapp->menu;
|
||||
}
|
||||
|
||||
void wApplicationSetMenu(WApplication *wapp, WMenu *menu) {
|
||||
wapp->menu = menu;
|
||||
}
|
||||
|
||||
struct WWindow *wApplicationGetMainWindowDesc(WApplication *wapp) {
|
||||
return wapp->main_window_desc;
|
||||
}
|
||||
|
||||
struct WAppIcon *wApplicationGetAppIcon(WApplication *wapp) {
|
||||
return wapp->app_icon;
|
||||
}
|
||||
void wApplicationSetAppIcon(WApplication *wapp, struct WAppIcon *icon) {
|
||||
wapp->app_icon = icon;
|
||||
}
|
||||
|
||||
int wApplicationGetLastWorkspace(WApplication *wapp) {
|
||||
return wapp->last_workspace;
|
||||
}
|
||||
void wApplicationSetLastWorkspace(WApplication *wapp, int workspace) {
|
||||
wapp->last_workspace = workspace;
|
||||
}
|
||||
|
||||
struct WWindow *wApplicationGetLastFocused(WApplication *wapp) {
|
||||
return wapp->last_focused;
|
||||
}
|
||||
void wApplicationSetLastFocused(WApplication *wapp, struct WWindow *win) {
|
||||
wapp->last_focused = win;
|
||||
}
|
||||
|
||||
|
||||
WMHandlerID *wApplicationGetUrgentBounceTimer(WApplication *wapp) {
|
||||
return wapp->urgent_bounce_timer;
|
||||
}
|
||||
int wApplicationHasUrgentBounceTimer(WApplication *wapp) {
|
||||
return wapp->urgent_bounce_timer != NULL;
|
||||
}
|
||||
void wApplicationClearUrgentBounceTimer(WApplication *wapp) {
|
||||
if (wapp->urgent_bounce_timer) {
|
||||
WMDeleteTimerHandler(wapp->urgent_bounce_timer);
|
||||
wapp->urgent_bounce_timer = NULL;
|
||||
}
|
||||
}
|
||||
void wApplicationSetUrgentBounceTimer(WApplication *wapp, WMHandlerID *timer) {
|
||||
wapp->urgent_bounce_timer = timer;
|
||||
}
|
||||
|
||||
int wApplicationGetSkipNextAnimation(WApplication *wapp) {
|
||||
return wapp->flags.skip_next_animation;
|
||||
}
|
||||
void wApplicationSetSkipNextAnimation(WApplication *wapp, int skip) {
|
||||
wapp->flags.skip_next_animation = !!skip;
|
||||
}
|
||||
|
||||
int wApplicationIsHidden(WApplication *wapp) {
|
||||
return wapp->flags.hidden;
|
||||
}
|
||||
void wApplicationSetHidden(WApplication *wapp, int hidden) {
|
||||
wapp->flags.hidden = !!hidden;
|
||||
}
|
||||
|
||||
int wApplicationIsEmulated(WApplication *wapp) {
|
||||
return wapp->flags.emulated;
|
||||
}
|
||||
void wApplicationSetEmulated(WApplication *wapp, int emulated) {
|
||||
wapp->flags.emulated = !!emulated;
|
||||
}
|
||||
|
||||
int wApplicationIsBouncing(WApplication *wapp) {
|
||||
return wapp->flags.bouncing;
|
||||
}
|
||||
void wApplicationSetBouncing(WApplication *wapp, int bouncing) {
|
||||
wapp->flags.bouncing = !!bouncing;
|
||||
}
|
||||
|
||||
/******** Construction/destruction ********/
|
||||
static WWindow *makeMainWindow(WScreen * scr, Window window)
|
||||
|
||||
10
wmakerlib/Cargo.toml
Normal file
10
wmakerlib/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "wmakerlib"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
x11 = "2.21.0"
|
||||
176
wmakerlib/src/application.rs
Normal file
176
wmakerlib/src/application.rs
Normal file
@@ -0,0 +1,176 @@
|
||||
use std::ffi::{c_int, c_void};
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct Flags {
|
||||
skip_next_animation: bool,
|
||||
hidden: bool,
|
||||
emulated: bool,
|
||||
bouncing: bool,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Application {
|
||||
next: *mut Application,
|
||||
prev: *mut Application,
|
||||
main_window: x11::xlib::Window,
|
||||
main_window_desc: *mut c_void,
|
||||
menu: *mut c_void,
|
||||
app_icon: *mut c_void,
|
||||
refcount: c_int,
|
||||
last_focused: *mut c_void,
|
||||
last_workspace: c_int,
|
||||
urgent_bounce_timer: *mut c_void,
|
||||
flags: Flags,
|
||||
}
|
||||
|
||||
pub mod ffi {
|
||||
use super::Application;
|
||||
use std::ffi::{c_int, c_void};
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationGetMainWindow(app: *mut Application) -> x11::xlib::Window {
|
||||
unsafe {
|
||||
(*app).main_window
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationGetMenu(app: *mut Application) -> *mut c_void {
|
||||
unsafe {
|
||||
(*app).menu
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationSetMenu(app: *mut Application, menu: *mut c_void) {
|
||||
unsafe {
|
||||
(*app).menu = menu;
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationGetMainWindowDesc(app: *mut Application) -> *mut c_void {
|
||||
unsafe {
|
||||
(*app).main_window_desc
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationGetAppIcon(app: *mut Application) -> *mut c_void {
|
||||
unsafe {
|
||||
(*app).app_icon
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationSetAppIcon(app: *mut Application, icon: *mut c_void) {
|
||||
unsafe {
|
||||
(*app).app_icon = icon;
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationGetLastWorkspace(app: *mut Application) -> c_int {
|
||||
unsafe {
|
||||
(*app).last_workspace
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationSetLastWorkspace(app: *mut Application, workspace: c_int) {
|
||||
unsafe {
|
||||
(*app).last_workspace = workspace;
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationGetLastFocused(app: *mut Application) -> *mut c_void {
|
||||
unsafe {
|
||||
(*app).last_focused
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationSetLastFocused(app: *mut Application, win: *mut c_void) {
|
||||
unsafe {
|
||||
(*app).last_focused = win;
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationGetUrgentBounceTimer(app: *mut Application) -> *mut c_void {
|
||||
unsafe {
|
||||
(*app).urgent_bounce_timer
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationHasUrgentBounceTimer(app: *mut Application) -> c_int {
|
||||
unsafe {
|
||||
if (*app).urgent_bounce_timer.is_null() { 0 } else { 1 }
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationSetUrgentBounceTimer(app: *mut Application, timer: *mut c_void) {
|
||||
unsafe {
|
||||
(*app).urgent_bounce_timer = timer;
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationGetSkipNextAnimation(app: *mut Application) -> c_int {
|
||||
unsafe {
|
||||
(*app).flags.skip_next_animation.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationSetSkipNextAnimation(app: *mut Application, skip: c_int) {
|
||||
unsafe {
|
||||
(*app).flags.skip_next_animation = skip != 0;
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationIsHidden(app: *mut Application) -> c_int {
|
||||
unsafe {
|
||||
(*app).flags.hidden.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationSetHidden(app: *mut Application, hidden: c_int) {
|
||||
unsafe {
|
||||
(*app).flags.hidden = hidden != 0;
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationIsEmulated(app: *mut Application) -> c_int {
|
||||
unsafe {
|
||||
(*app).flags.emulated.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationSetEmulated(app: *mut Application, emulated: c_int) {
|
||||
unsafe {
|
||||
(*app).flags.emulated = emulated != 0;
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationIsBouncing(app: *mut Application) -> c_int {
|
||||
unsafe {
|
||||
(*app).flags.bouncing.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wApplicationSetBouncing(app: *mut Application, bouncing: c_int) {
|
||||
unsafe {
|
||||
(*app).flags.bouncing = bouncing != 0
|
||||
}
|
||||
}
|
||||
}
|
||||
4
wmakerlib/src/lib.rs
Normal file
4
wmakerlib/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod application;
|
||||
|
||||
pub type WApplication = application::Application;
|
||||
pub use application::ffi::*;
|
||||
Reference in New Issue
Block a user