From ad6df6e3fde16445b6755f56522b235d61b36e57 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 25 Nov 2025 11:16:05 +0900 Subject: [PATCH] windows support --- mauplay/audio.c | 12 ++++++------ mauplay/db.c | 13 +++++++------ mauplay/mauplay.h | 15 ++++++--------- mauplay/ui.c | 49 ++++++++++++++++++++++++----------------------- mbiff/mail.c | 13 +++++++------ mbiff/mbiff.h | 2 -- 6 files changed, 51 insertions(+), 53 deletions(-) diff --git a/mauplay/audio.c b/mauplay/audio.c index 19734d2..1292b70 100644 --- a/mauplay/audio.c +++ b/mauplay/audio.c @@ -4,7 +4,7 @@ #include static MDEAudio audio; -pthread_mutex_t audio_mutex; +MDEMutex audio_mutex; queue_t* queue = NULL; int queue_seek = -1; int paused = 0; @@ -13,7 +13,7 @@ int repeated = 0; static void handler(MDEAudio handle, void* user, void* data, int frames) { memset(data, 0, frames * 2 * 2); - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); if(queue_seek != -1 && !paused) { int from_frames = frames * queue[queue_seek].sound->context->sample_rate / MDEAudioRate; float* from = malloc(from_frames * sizeof(*from) * 2); @@ -47,13 +47,13 @@ static void handler(MDEAudio handle, void* user, void* data, int frames) { } } } - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } void audio_init(void) { audio = MDEAudioOpen(handler, NULL); - pthread_mutex_init(&audio_mutex, NULL); + audio_mutex = MDEMutexCreate(); MDEAudioStart(audio); } @@ -64,10 +64,10 @@ void audio_queue(const char* path) { q.sound = MDESoundOpen(q.path); q.frames = 0; - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); arrput(queue, q); if(queue_seek == -1) queue_seek = arrlen(queue) - 1; ui_set_play_queue(arrlen(queue)); - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } diff --git a/mauplay/db.c b/mauplay/db.c index b782cbb..7884c25 100644 --- a/mauplay/db.c +++ b/mauplay/db.c @@ -29,13 +29,14 @@ int db_exec(const char* s) { } int db_init(void) { - struct passwd* pwd = getpwuid(getuid()); - char* dir = malloc(strlen(pwd->pw_dir) + 1 + strlen(".config/mauplay") + 1); - char* path; - int st = 0; + char* conf = MDEDirectoryConfigPath(); + char* dir = malloc(strlen(conf) + 8 + 1); + char* path; + int st = 0; - strcpy(dir, pwd->pw_dir); - strcat(dir, "/.config/mauplay"); + strcpy(dir, conf); + strcat(dir, "/mauplay"); + free(conf); MDEDirectoryCreate(dir, 0755); diff --git a/mauplay/mauplay.h b/mauplay/mauplay.h index 4083b1a..4e34e2e 100644 --- a/mauplay/mauplay.h +++ b/mauplay/mauplay.h @@ -12,12 +12,9 @@ /* External */ /* Standard */ -#include -#include -#include #include #include -#include +#include #define ALBUMWIDTH 128 @@ -73,11 +70,11 @@ void ui_set_artists(int v); void ui_set_genres(int v); /* audio.c */ -extern pthread_mutex_t audio_mutex; -extern queue_t* queue; -extern int queue_seek; -extern int paused; -extern int repeated; +extern MDEMutex audio_mutex; +extern queue_t* queue; +extern int queue_seek; +extern int paused; +extern int repeated; void audio_init(void); void audio_queue(const char* path); diff --git a/mauplay/ui.c b/mauplay/ui.c index 29e9624..d00cead 100644 --- a/mauplay/ui.c +++ b/mauplay/ui.c @@ -105,7 +105,7 @@ static void tree_activate(MwWidget handle, void* user, void* client) { if(current != NULL) free(current); current = NULL; if(client == play_queue) { - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); for(i = 0; i < arrlen(queue); i++) { char buf[64]; int ind = shgeti(db_musics, queue[i].path); @@ -121,7 +121,7 @@ static void tree_activate(MwWidget handle, void* user, void* client) { MwListBoxPacketSet(p, index, 3, buf); } - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } if(client == all_music) { for(i = 0; i < shlen(db_musics); i++) { @@ -203,7 +203,7 @@ static void tree_activate(MwWidget handle, void* user, void* client) { static void list_activate(MwWidget handle, void* user, void* client) { if(ui_last == play_queue) { - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); if(queue_seek != -1) { queue[queue_seek].frames = 0; MDESoundSeek(queue[queue_seek].sound, 0); @@ -211,7 +211,7 @@ static void list_activate(MwWidget handle, void* user, void* client) { queue_seek = (*(int*)client) - 1; queue[queue_seek].frames = 0; MDESoundSeek(queue[queue_seek].sound, 0); - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } else if(ui_last == all_music) { audio_queue(db_musics[(*(int*)client) - 1].key); } else if(ui_last == albums || ui_last == artists || ui_last == genres) { @@ -284,7 +284,7 @@ static void list_activate(MwWidget handle, void* user, void* client) { int queue_last = -1; static void window_tick(MwWidget handle, void* user, void* client) { - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); if(queue_last != queue_seek && queue_seek != -1) { int ind; char* buf; @@ -320,12 +320,13 @@ static void window_tick(MwWidget handle, void* user, void* client) { MwForceRender(album); if(ui_last == play_queue) { - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); MwDispatchUserHandler(tree, MwNactivateHandler, ui_last); - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); } ind = shgeti(db_musics, queue[queue_seek].path); + buf = malloc(strlen(db_musics[ind].title) + 1 + strlen(db_musics[ind].artist) + 1); buf[0] = 0; @@ -373,7 +374,7 @@ static void window_tick(MwWidget handle, void* user, void* client) { MwForceRender(album); } queue_last = queue_seek; - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } static void seekbar_changed(MwWidget handle, void* user, void* client) { @@ -381,7 +382,7 @@ static void seekbar_changed(MwWidget handle, void* user, void* client) { } static void bskipback_activate(MwWidget handle, void* user, void* client) { - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); if(queue_seek == -1) { queue_seek = 0; } else { @@ -393,33 +394,33 @@ static void bskipback_activate(MwWidget handle, void* user, void* client) { } else { queue_seek = -1; } - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } static void bplay_activate(MwWidget handle, void* user, void* client) { - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); paused = 0; - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } static void bpause_activate(MwWidget handle, void* user, void* client) { - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); paused = 1; - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } static void bstop_activate(MwWidget handle, void* user, void* client) { - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); if(queue_seek != -1) { queue[queue_seek].frames = 0; MDESoundSeek(queue[queue_seek].sound, 0); } queue_seek = -1; - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } static void bskipfwd_activate(MwWidget handle, void* user, void* client) { - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); if(queue_seek == -1) { queue_seek = 0; } else { @@ -431,16 +432,16 @@ static void bskipfwd_activate(MwWidget handle, void* user, void* client) { } else { queue_seek = -1; } - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } static void brepeat_activate(MwWidget handle, void* user, void* client) { - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); repeated = repeated ? 0 : 1; MwVaApply(brepeat, MwNpixmap, repeated ? pxrepeatsong : pxrepeat, NULL); - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } static void file_fc_chosen(MwWidget handle, void* user, void* client) { @@ -459,7 +460,7 @@ static void menu_menu(MwWidget handle, void* user, void* client) { } else if(client == file_add_playlist) { MwWidget fc = MwFileChooser(window, "Choose a playlist to add"); MwAddUserHandler(fc, MwNfileChosenHandler, playlist_fc_chosen, NULL); - }else if(client == help_about){ + } else if(client == help_about) { MDEAboutDialog(window, "mauplay", VERSION, pxradio); } } @@ -471,7 +472,7 @@ static void list_mouseup(MwWidget handle, void* user, void* client) { if(m->button != MwLLMouseRight) return; if((s = MwGetInteger(list, MwNvalue)) == -1) return; - pthread_mutex_lock(&audio_mutex); + MDEMutexLock(audio_mutex); MwListBoxDelete(list, s); arrdel(queue, s - 1); ui_set_play_queue(arrlen(queue)); @@ -485,7 +486,7 @@ static void list_mouseup(MwWidget handle, void* user, void* client) { if(arrlen(queue) <= queue_seek) { queue_seek = arrlen(queue) - 1; } - pthread_mutex_unlock(&audio_mutex); + MDEMutexUnlock(audio_mutex); } void ui_init(void) { @@ -498,7 +499,7 @@ void ui_init(void) { file_add_directory = MwMenuAdd(menu, m, "Add Directory"); file_add_playlist = MwMenuAdd(menu, m, "Add Playlist"); - m = MwMenuAdd(menu, NULL, "?Help"); + m = MwMenuAdd(menu, NULL, "?Help"); help_about = MwMenuAdd(menu, m, "About"); ui_list_reset(NULL); diff --git a/mbiff/mail.c b/mbiff/mail.c index 784a05a..9bb2474 100644 --- a/mbiff/mail.c +++ b/mbiff/mail.c @@ -4,16 +4,17 @@ static time_t last = 0; static char* mailpath; void init_mail(void) { - struct stat s; - struct passwd* pwd = getpwuid(getuid()); + struct stat s; + char* name = MDEUsersGetUsername(); if(getenv("MAIL") != NULL) { - mailpath = malloc(strlen(getenv("MAIL")) + strlen(pwd->pw_name) + 1); - sprintf(mailpath, getenv("MAIL"), pwd->pw_name); + mailpath = malloc(strlen(getenv("MAIL")) + strlen(name) + 1); + sprintf(mailpath, getenv("MAIL"), name); } else { - mailpath = malloc(strlen(_PATH_MAILDIR) + 1 + strlen(pwd->pw_name) + 1); - sprintf(mailpath, _PATH_MAILDIR "/%s", pwd->pw_name); + mailpath = malloc(strlen(_PATH_MAILDIR) + 1 + strlen(name) + 1); + sprintf(mailpath, _PATH_MAILDIR "/%s", name); } + free(name); if(stat(mailpath, &s) == 0) { last = s.st_mtime; diff --git a/mbiff/mbiff.h b/mbiff/mbiff.h index 4d7d9b6..5059349 100644 --- a/mbiff/mbiff.h +++ b/mbiff/mbiff.h @@ -11,8 +11,6 @@ /* Standard */ #include -#include -#include #include #include