From b608931b21f7c1278bf6b0c5738c2363c15e91f5 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Fri, 17 Oct 2025 19:44:55 +0000 Subject: [PATCH] stuff git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@403 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/String.h | 15 +++++++++++++++ include/Mw/TypeDefs.h | 1 + src/backend/gdi.c | 22 +++++++++++----------- src/backend/x11.c | 26 +++++++++++++------------- src/core.c | 11 ++++++----- src/cursor/hidden.c | 38 ++------------------------------------ src/directory.c | 3 ++- src/filechooser.c | 22 ++++++++-------------- src/string.c | 19 +++++++++++++++++++ src/widget/listbox.c | 2 ++ 10 files changed, 79 insertions(+), 80 deletions(-) diff --git a/include/Mw/String.h b/include/Mw/String.h index 9190b16..7244d07 100644 --- a/include/Mw/String.h +++ b/include/Mw/String.h @@ -7,6 +7,7 @@ #define __MW_STRING_H__ #include +#include #ifdef __cplusplus extern "C" { @@ -27,6 +28,20 @@ MWDECL char* MwStringDupliacte(const char* str); */ MWDECL char* MwStringConcat(const char* str1, const char* str2); +/*! + * %brief Converts size to string + * %param out Output + * %param size Size + */ +MWDECL void MwStringSize(char* out, MwOffset size); + +/*! + * %brief Converts time to string + * %param out Output + * %param t Time + */ +MWDECL void MwStringTime(char* out, time_t t); + #ifdef __cplusplus } #endif diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index a936bdc..92220ac 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -157,6 +157,7 @@ struct _MwDirectoryEntry { char* name; int type; MwOffset size; + time_t mtime; }; #define MwCursorDataHeight 16 diff --git a/src/backend/gdi.c b/src/backend/gdi.c index cac30ad..96e61a7 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -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); } diff --git a/src/backend/x11.c b/src/backend/x11.c index 86513a7..6b32566 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -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; } } diff --git a/src/core.c b/src/core.c index 434073b..2057b26 100644 --- a/src/core.c +++ b/src/core.c @@ -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); } diff --git a/src/cursor/hidden.c b/src/cursor/hidden.c index 1dd4e2a..66a7aa7 100644 --- a/src/cursor/hidden.c +++ b/src/cursor/hidden.c @@ -1,40 +1,6 @@ /* $Id$ */ #include 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}}; diff --git a/src/directory.c b/src/directory.c index 5b84796..76482bd 100644 --- a/src/directory.c +++ b/src/directory.c @@ -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 diff --git a/src/filechooser.c b/src/filechooser.c index 525e1be..890c123 100644 --- a/src/filechooser.c +++ b/src/filechooser.c @@ -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); diff --git a/src/string.c b/src/string.c index 7d07505..0b21ba1 100644 --- a/src/string.c +++ b/src/string.c @@ -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); +} diff --git a/src/widget/listbox.c b/src/widget/listbox.c index 9ad96fc..44e2648 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -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; }