forked from vitrine/wmaker
Compare commits
9 Commits
riir
...
refactor/r
| Author | SHA1 | Date | |
|---|---|---|---|
| a39123bbd1 | |||
| 464a82b13c | |||
| 3d7f0618f0 | |||
| 41a10ee6c9 | |||
| 000dd929bf | |||
| 1a791f93d3 | |||
| 9933450b63 | |||
| 5883e0d8a3 | |||
| 7878215c19 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -155,6 +155,8 @@ WPrefs.app/WPrefs.desktop
|
||||
WINGs/wings-rs-tests/Cargo.lock
|
||||
WINGs/wings-rs/Cargo.lock
|
||||
WINGs/wings-rs/src/WINGsP.rs
|
||||
WINGs/wings-rs/src/WINGsP/constants.rs
|
||||
WINGs/wings-rs/src/WINGsP/mod.rs
|
||||
wmaker-rs/Cargo.lock
|
||||
wrlib-rs/src/ffi.rs
|
||||
wutil-rs/Cargo.lock
|
||||
|
||||
@@ -427,8 +427,6 @@ struct W_Color {
|
||||
} flags;
|
||||
};
|
||||
|
||||
#define W_PIXEL(c) (c)->color.pixel
|
||||
|
||||
|
||||
/* ---[ wevent.c ]-------------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ char* wtrimspace(const char *s);
|
||||
*/
|
||||
char *wshellquote(const char *s);
|
||||
|
||||
/* ---[ WINGs/misc.c ]--------------------------------------------------- */
|
||||
/* ---[ wutil-rs/src/range.rs ]------------------------------------------ */
|
||||
|
||||
WMRange wmkrange(int start, int count);
|
||||
|
||||
|
||||
10
WINGs/misc.c
10
WINGs/misc.c
@@ -24,16 +24,6 @@
|
||||
|
||||
#include "error.h"
|
||||
|
||||
WMRange wmkrange(int start, int count)
|
||||
{
|
||||
WMRange range;
|
||||
|
||||
range.position = start;
|
||||
range.count = count;
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
/*
|
||||
* wutil_shutdown - cleanup in WUtil when user program wants to exit
|
||||
*/
|
||||
|
||||
@@ -725,14 +725,14 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
|
||||
gcv.graphics_exposures = False;
|
||||
|
||||
gcv.function = GXxor;
|
||||
gcv.foreground = W_PIXEL(scrPtr->white);
|
||||
gcv.foreground = scrPtr->white->color.pixel;
|
||||
if (gcv.foreground == 0)
|
||||
gcv.foreground = 1;
|
||||
scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
|
||||
| GCGraphicsExposures | GCForeground, &gcv);
|
||||
|
||||
gcv.function = GXxor;
|
||||
gcv.foreground = W_PIXEL(scrPtr->gray);
|
||||
gcv.foreground = scrPtr->gray->color.pixel;
|
||||
gcv.subwindow_mode = IncludeInferiors;
|
||||
scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
|
||||
| GCGraphicsExposures | GCForeground | GCSubwindowMode, &gcv);
|
||||
@@ -743,8 +743,8 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
|
||||
scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
|
||||
|
||||
stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
|
||||
gcv.foreground = W_PIXEL(scrPtr->darkGray);
|
||||
gcv.background = W_PIXEL(scrPtr->gray);
|
||||
gcv.foreground = scrPtr->darkGray->color.pixel;
|
||||
gcv.background = scrPtr->gray->color.pixel;
|
||||
gcv.fill_style = FillStippled;
|
||||
gcv.stipple = stipple;
|
||||
scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
|
||||
|
||||
@@ -47,7 +47,7 @@ src/WINGsP.rs: ../WINGs/WINGsP.h ../../wrlib/wraster.h ../WINGs/WINGs.h ../WINGs
|
||||
--allowlist-type "^WM(Button|ButtonBehaviorMask)" \
|
||||
--allowlist-function "^WM(CreateCustomButton|SetButtonText|SetButtonAction|SetButtonText)" \
|
||||
--allowlist-function "wmkrange" \
|
||||
--allowlist-type "^WM(View|Array|DragOperationType|Point|Data|OpenPanel|SavePanel|HashTable|DraggingInfo|SelectionProcs|Rect|EventProc|Widget|Size|Color|Pixmap|FilePanel|Screen|Range|List|ListItem)" \
|
||||
--allowlist-type "^WM(View|Array|DragOperationType|Point|Data|OpenPanel|SavePanel|HashTable|DraggingInfo|SelectionProcs|Rect|EventProc|Widget|Size|Color|Pixmap|FilePanel|Screen|List|ListItem)" \
|
||||
--allowlist-type "^R(Context|ContextAttributes|Image|RenderingMode|ScalingFilter|StdColormapMode|ImageFormat|Color)" \
|
||||
--allowlist-type "_WINGsConfiguration" \
|
||||
--allowlist-item "^WMAlignment" \
|
||||
|
||||
@@ -15,7 +15,7 @@ fi
|
||||
FILE="$1"
|
||||
|
||||
exec sed -i -r \
|
||||
-e "1s/^/use x11::xlib::*;\nuse crate::font::ffi::WMFont;\n\n/" \
|
||||
-e "1s/^/use wutil_rs::range::ffi::*;\nuse x11::xlib::*;\nuse crate::font::ffi::WMFont;\n\n/" \
|
||||
-e "s/_XftDraw/::std::ffi::c_void/g" \
|
||||
-e "s/_XftFont/::std::ffi::c_void/g" \
|
||||
-e "s/PangoLayout/::std::ffi::c_void/g" \
|
||||
|
||||
@@ -741,10 +741,10 @@ impl FontPanel {
|
||||
return;
|
||||
}
|
||||
WMSetTextFieldText(self.size_text.as_ptr(), (*item).text);
|
||||
let Ok(len) = CStr::from_ptr((*item).text).count_bytes().try_into() else {
|
||||
let Ok(len) = TryInto::<c_int>::try_into(CStr::from_ptr((*item).text).count_bytes()) else {
|
||||
return;
|
||||
};
|
||||
WMSelectTextFieldRange(self.size_text.as_ptr(), wmkrange(0, len));
|
||||
WMSelectTextFieldRange(self.size_text.as_ptr(), wutil_rs::range::Range::from(0..len));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2989,8 +2989,8 @@ WMText *WMCreateTextForDocumentType(WMWidget * parent, WMAction * parser, WMActi
|
||||
W_SetViewBackgroundColor(tPtr->view, tPtr->bgColor);
|
||||
|
||||
gcv.graphics_exposures = False;
|
||||
gcv.foreground = W_PIXEL(scr->gray);
|
||||
gcv.background = W_PIXEL(scr->darkGray);
|
||||
gcv.foreground = scr->gray->color.pixel;
|
||||
gcv.background = scr->darkGray->color.pixel;
|
||||
gcv.fill_style = FillStippled;
|
||||
/* why not use scr->stipple here? */
|
||||
gcv.stipple = XCreateBitmapFromData(dpy, W_DRAWABLE(scr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
|
||||
|
||||
@@ -102,8 +102,8 @@ static W_View *createView(W_Screen * screen, W_View * parent)
|
||||
|
||||
view->attribFlags |= CWBackPixel | CWColormap | CWBorderPixel | CWBackPixmap;
|
||||
view->attribs.background_pixmap = None;
|
||||
view->attribs.background_pixel = W_PIXEL(screen->gray);
|
||||
view->attribs.border_pixel = W_PIXEL(screen->black);
|
||||
view->attribs.background_pixel = screen->gray->color.pixel;
|
||||
view->attribs.border_pixel = screen->black->color.pixel;
|
||||
view->attribs.colormap = screen->colormap;
|
||||
|
||||
view->backColor = WMRetainColor(screen->gray);
|
||||
@@ -491,9 +491,9 @@ void W_SetViewBackgroundColor(W_View * view, WMColor * color)
|
||||
|
||||
view->attribFlags |= CWBackPixel;
|
||||
view->attribFlags &= ~CWBackPixmap;
|
||||
view->attribs.background_pixel = W_PIXEL(color);
|
||||
view->attribs.background_pixel = color->color.pixel;
|
||||
if (view->flags.realized) {
|
||||
XSetWindowBackground(view->screen->display, view->window, W_PIXEL(color));
|
||||
XSetWindowBackground(view->screen->display, view->window, color->color.pixel);
|
||||
XClearWindow(view->screen->display, view->window);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ wmsetbg_LDADD = \
|
||||
$(top_builddir)/wrlib/libwraster.la \
|
||||
-lwings_rs \
|
||||
-lwutil_rs \
|
||||
$(top_builddir)/WINGs/libWINGs.la \
|
||||
@XLFLAGS@ @LIBXINERAMA@ @XLIBS@ @INTLIBS@ @FCLIBS@ @PANGO_LIBS@
|
||||
|
||||
wmgenmenu_LDFLAGS = \
|
||||
|
||||
@@ -13,6 +13,7 @@ RUST_SOURCES = \
|
||||
src/memory.rs \
|
||||
src/notification.rs \
|
||||
src/prop_list.rs \
|
||||
src/range.rs \
|
||||
src/sendable.rs \
|
||||
src/string.rs \
|
||||
src/tree.rs
|
||||
|
||||
@@ -8,6 +8,7 @@ pub mod hash_table;
|
||||
pub mod memory;
|
||||
pub mod notification;
|
||||
pub mod prop_list;
|
||||
pub mod range;
|
||||
pub mod sendable;
|
||||
pub mod string;
|
||||
pub mod tree;
|
||||
|
||||
58
wutil-rs/src/range.rs
Normal file
58
wutil-rs/src/range.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
use std::ffi::c_int;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||
#[repr(C)]
|
||||
pub struct Range {
|
||||
pub start: c_int,
|
||||
pub count: c_int,
|
||||
}
|
||||
|
||||
impl Into<std::ops::Range<c_int>> for Range {
|
||||
fn into(self) -> std::ops::Range<c_int> {
|
||||
self.start..(self.start + self.count)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::ops::Range<c_int>> for Range {
|
||||
fn from(other: std::ops::Range<c_int>) -> Range {
|
||||
Range {
|
||||
start: other.start,
|
||||
count: other.end - other.start
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::ffi::c_int;
|
||||
use super::Range;
|
||||
|
||||
#[test]
|
||||
fn from_std_range() {
|
||||
assert_eq!(Range { start: 0, count: 10 }, Range::from(0..10));
|
||||
assert_eq!(Range { start: 1, count: 9 }, Range::from(1..10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_std_range() {
|
||||
assert_eq!(0..10, Into::<std::ops::Range<c_int>>::into(Range {
|
||||
start: 0,
|
||||
count: 10
|
||||
}));
|
||||
assert_eq!(1..10, Into::<std::ops::Range<c_int>>::into(Range {
|
||||
start: 1,
|
||||
count: 9
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
pub mod ffi {
|
||||
use std::ffi::c_int;
|
||||
|
||||
pub type WMRange = super::Range;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn wmkrange(start: c_int, count: c_int) -> WMRange {
|
||||
WMRange { start, count }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user