git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@403 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-17 19:44:55 +00:00
parent f9b061aac8
commit b608931b21
10 changed files with 79 additions and 80 deletions

View File

@@ -91,7 +91,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
p.x = LOWORD(lp);
p.y = HIWORD(lp);
if(u->ll->grabbed){
if(u->ll->grabbed) {
RECT rc;
GetClientRect(hWnd, &rc);
@@ -101,8 +101,8 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
MwLLDispatch(u->ll, move, &p);
if(u->ll->grabbed && (p.x != 0 || p.y != 0)){
RECT rc;
if(u->ll->grabbed && (p.x != 0 || p.y != 0)) {
RECT rc;
POINT p;
GetClientRect(hWnd, &rc);
@@ -130,9 +130,9 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
int n = wp;
MwLLDispatch(u->ll, key, &n);
}else if(msg == WM_SETFOCUS){
} else if(msg == WM_SETFOCUS) {
MwLLDispatch(u->ll, focus_in, NULL);
}else if(msg == WM_KILLFOCUS){
} else if(msg == WM_KILLFOCUS) {
MwLLDispatch(u->ll, focus_out, NULL);
} else if(msg == WM_KEYDOWN || msg == WM_KEYUP) {
int n = -1;
@@ -212,7 +212,7 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
RegisterClassEx(&wc);
r->grabbed = 0;
r->grabbed = 0;
r->copy_buffer = 1;
r->hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->hWnd, 0, wc.hInstance, NULL);
r->hInstance = wc.hInstance;
@@ -589,14 +589,14 @@ long MwLLGetTick(void) {
return GetTickCount();
}
void MwLLFocus(MwLL handle){
void MwLLFocus(MwLL handle) {
SetFocus(handle->hWnd);
}
void MwLLGrabPointer(MwLL handle, int toggle){
if(toggle){
void MwLLGrabPointer(MwLL handle, int toggle) {
if(toggle) {
POINT p;
RECT rc;
RECT rc;
GetClientRect(handle->hWnd, &rc);
@@ -616,7 +616,7 @@ void MwLLGrabPointer(MwLL handle, int toggle){
ClipCursor(&rc);
SetCursorPos(p.x, p.y);
}else{
} else {
handle->grabbed = 0;
ClipCursor(NULL);
}

View File

@@ -286,12 +286,12 @@ void MwLLNextEvent(MwLL handle) {
if(ev.xclient.data.l[0] == (long)handle->wm_delete) {
MwLLDispatch(handle, close, NULL);
}
} else if(ev.type == FocusIn){
} else if(ev.type == FocusIn) {
MwLLDispatch(handle, focus_in, NULL);
} else if(ev.type == FocusOut){
} else if(ev.type == FocusOut) {
MwLLDispatch(handle, focus_out, NULL);
} else if(ev.type == MotionNotify) {
MwPoint p;
MwPoint p;
XWindowAttributes attr;
XGetWindowAttributes(handle->display, handle->window, &attr);
@@ -299,13 +299,13 @@ void MwLLNextEvent(MwLL handle) {
p.x = ev.xmotion.x;
p.y = ev.xmotion.y;
if(handle->grabbed){
if(handle->grabbed) {
p.x -= attr.width / 2;
p.y -= attr.height / 2;
}
MwLLDispatch(handle, move, &p);
if(handle->grabbed && (p.x != 0 || p.y != 0)){
if(handle->grabbed && (p.x != 0 || p.y != 0)) {
XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
}
} else if(ev.type == KeyPress || ev.type == KeyRelease) {
@@ -343,13 +343,13 @@ void MwLLNextEvent(MwLL handle) {
n = MwLLKeyUp;
} else if(strcmp(str, "Down") == 0) {
n = MwLLKeyDown;
} else if(strcmp(str, "Return") == 0){
} else if(strcmp(str, "Return") == 0) {
n = MwLLKeyEnter;
} else if(strcmp(str, "Escape") == 0){
} else if(strcmp(str, "Escape") == 0) {
n = MwLLKeyEscape;
}else if(strcmp(str, "Shift_L") == 0){
} else if(strcmp(str, "Shift_L") == 0) {
n = MwLLKeyLeftShift;
}else if(strcmp(str, "Shift_R") == 0){
} else if(strcmp(str, "Shift_R") == 0) {
n = MwLLKeyRightShift;
}
@@ -690,20 +690,20 @@ long MwLLGetTick(void) {
return n;
}
void MwLLFocus(MwLL handle){
void MwLLFocus(MwLL handle) {
XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime);
}
void MwLLGrabPointer(MwLL handle, int toggle){
void MwLLGrabPointer(MwLL handle, int toggle) {
XWindowAttributes attr;
XGetWindowAttributes(handle->display, handle->window, &attr);
if(toggle){
if(toggle) {
handle->grabbed = 1;
XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
}else{
} else {
handle->grabbed = 0;
}
}

View File

@@ -139,8 +139,8 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->lowlevel->handler->move = llmovehandler;
h->lowlevel->handler->key = llkeyhandler;
h->lowlevel->handler->key_released = llkeyrelhandler;
h->lowlevel->handler->focus_in = llfocusinhandler;
h->lowlevel->handler->focus_out = llfocusouthandler;
h->lowlevel->handler->focus_in = llfocusinhandler;
h->lowlevel->handler->focus_out = llfocusouthandler;
}
if(parent != NULL) arrput(parent->children, h);
@@ -414,7 +414,7 @@ void MwSetDefault(MwWidget handle) {
inherit_text(handle, MwNforeground, MwDefaultForeground);
}
void MwHideCursor(MwWidget handle){
void MwHideCursor(MwWidget handle) {
MwLLSetCursor(handle->lowlevel, &MwCursorHidden, &MwCursorHiddenMask);
}
@@ -478,10 +478,11 @@ void MwAddTickList(MwWidget handle) {
arrput(root->tick_list, handle);
}
void MwFocus(MwWidget handle){
void MwFocus(MwWidget handle) {
MwLLFocus(handle->lowlevel);
}
void MwGrabPointer(MwWidget handle, int toggle){
void MwGrabPointer(MwWidget handle, int toggle) {
if(toggle) MwFocus(handle);
MwLLGrabPointer(handle->lowlevel, toggle);
}

View File

@@ -1,40 +1,6 @@
/* $Id$ */
#include <Mw/Milsko.h>
MwCursor MwCursorHidden = {
1, 1, 0, -1, {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}};
1, 1, 0, -1, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
MwCursor MwCursorHiddenMask = {
1, 1, 0, -1, {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}};
1, 1, 0, -1, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

View File

@@ -98,7 +98,8 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) {
} else {
entry->type = MwDIRECTORY_FILE;
}
entry->size = s.st_size;
entry->size = s.st_size;
entry->mtime = s.st_mtime;
free(p);
#endif

View File

@@ -43,7 +43,7 @@ static void cancel(MwWidget handle, void* user, void* call) {
destroy(handle->parent);
}
static void cancel_window(MwWidget handle, void* user, void* call){
static void cancel_window(MwWidget handle, void* user, void* call) {
(void)user;
(void)call;
@@ -284,8 +284,12 @@ static void scan(MwWidget handle, const char* path) {
for(i = 0; i < arrlen(entries); i++) {
if(strcmp(entries[i]->name, ".") == 0 || strcmp(entries[i]->name, "..") == 0) continue;
if(entries[i]->type == MwDIRECTORY_DIRECTORY) {
char* date = malloc(128);
MwStringTime(date, entries[i]->mtime);
arrput(names, entries[i]->name);
arrput(dates, NULL);
arrput(dates, date);
arrput(sizes, NULL);
arrput(icons, fc->dir);
}
@@ -295,18 +299,8 @@ static void scan(MwWidget handle, const char* path) {
char* date = malloc(128);
char* size = malloc(128);
memset(date, 0, 128);
memset(size, 0, 128);
if(entries[i]->size / 1024 == 0) {
sprintf(size, "%d", (int)entries[i]->size);
} else if(entries[i]->size / 1024 / 1024 == 0) {
sprintf(size, "%.1fK", (double)entries[i]->size / 1024);
} else if(entries[i]->size / 1024 / 1024 / 1024 == 0) {
sprintf(size, "%.1fM", (double)entries[i]->size / 1024 / 1024);
} else {
sprintf(size, "%.1fG", (double)entries[i]->size / 1024 / 1024 / 1024);
}
MwStringTime(date, entries[i]->mtime);
MwStringSize(size, entries[i]->size);
arrput(names, entries[i]->name);
arrput(dates, date);

View File

@@ -15,3 +15,22 @@ char* MwStringConcat(const char* str1, const char* str2) {
return r;
}
void MwStringSize(char* out, MwOffset size) {
if(size / 1024 == 0) {
sprintf(out, "%d", (int)size);
} else if(size / 1024 / 1024 == 0) {
sprintf(out, "%.1fK", (double)size / 1024);
} else if(size / 1024 / 1024 / 1024 == 0) {
sprintf(out, "%.1fM", (double)size / 1024 / 1024);
} else {
sprintf(out, "%.1fG", (double)size / 1024 / 1024 / 1024);
}
}
void MwStringTime(char* out, time_t t) {
struct tm* tm = localtime(&t);
const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
sprintf(out, "%s %2d %02d:%02d %d", months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, 1900 + tm->tm_year);
}

View File

@@ -171,6 +171,8 @@ static void frame_draw(MwWidget handle) {
p.x += MwDefaultBorderWidth;
MwDrawText(handle, &p, lb->list[i].name[j], 0, MwALIGNMENT_BEGINNING, selected ? base : text);
p.x += get_col_width(lb, j) - MwDefaultBorderWidth;
if(j == 0) p.x -= MwGetInteger(handle->parent, MwNleftPadding);
}
p.y += MwTextHeight(handle, "M") / 2;
}