so far so good

This commit is contained in:
Nishi 2025-11-16 18:02:03 +09:00
commit 3b55fb0c38
Signed by: nishi
GPG key ID: 27EF69B208EB9343
8 changed files with 2018 additions and 19 deletions

View file

@ -21,7 +21,7 @@ PKGCONF_ADD(mdm inih)
target_link_libraries(
mdm
PRIVATE
pam MDELib Mw
pam pthread MDELib Mw
)

View file

@ -5,6 +5,8 @@
char* config_picture = NULL;
static int dumper(void* user, const char* section, const char* name, const char* value){
(void)user;
if(strcmp(section, "MDM Config") != 0) return 1;
if(strcmp(name, "Picture") == 0) config_picture = MDEStringDuplicate(value);

View file

@ -1,6 +1,6 @@
#include "mdm.h"
#include <Mw/Milsko.h>
MwWidget root;
static void add_user(const char* name, void* user){
MwComboBoxAdd(user, -1, name);
@ -11,10 +11,11 @@ void login_window(void){
MwLLPixmap p;
MwLibraryInit();
root = MwCreateWidget(NULL, "root", NULL, 0, 0, 0, 0);
window = MwVaCreateWidget(MwWindowClass, "login", NULL, (x_width() - 366) / 2, (x_height() - 183) / 2, 366, 183,
MwNhasBorder, 1,
MwNinverted, 0,
window = MwVaCreateWidget(MwWindowClass, "login", root, (x_width() - 366) / 2, (x_height() - 183) / 2, 366, 183,
MwNtitle, "login",
NULL);
p = config_picture == NULL ? NULL : MwLoadImage(window, config_picture);
pic = MwVaCreateWidget(MwImageClass, "image", window, 10, 10, 80, 137,
@ -41,7 +42,7 @@ void login_window(void){
MwNorientation, MwHORIZONTAL,
NULL);
shutdown = MwVaCreateWidget(MwButtonClass, "shutdown", window, 10, 10+137+10, 80, 18,
MwNtext, "Shutdown",
MwNtext, "Shut Down",
NULL);
reboot = MwVaCreateWidget(MwButtonClass, "reboot", window, 10+80+5, 10+137+10, 70, 18,
MwNtext, "Reboot",
@ -54,5 +55,16 @@ void login_window(void){
MDEListUsers(add_user, usercombo);
MwLoop(window);
while(1){
int s = 0;
pthread_mutex_lock(&xmutex);
while(MwPending(root)){
if((s = MwStep(root)) != 0) break;
}
pthread_mutex_unlock(&xmutex);
if(s != 0) break;
MwTimeSleep(30);
}
}

View file

@ -25,7 +25,7 @@ int main(int argc, char** argv){
if((st = launch_x()) != 0) return st;
}
init_x();
if((st = init_x()) != 0) return st;
login_window();
}

View file

@ -4,6 +4,9 @@
#include "config.h"
#include <MDE/Foundation.h>
#include <Mw/Milsko.h>
#include <X11/Xlib.h>
#include <string.h>
#include <unistd.h>
@ -13,14 +16,22 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
/* xserver.c */
extern pthread_t xthread;
extern pthread_mutex_t xmutex;
extern Display* xdisplay;
int launch_x(void);
int x_width(void);
int x_height(void);
void init_x(void);
int init_x(void);
void x_loop(void);
/* login.c */
extern MwWidget root;
void login_window(void);
/* config.c */

2
mdm/stb_ds.c Normal file
View file

@ -0,0 +1,2 @@
#define STB_DS_IMPLEMENTATION
#include "stb_ds.h"

1895
mdm/stb_ds.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,19 @@
#define _MILSKO
#define USE_X11
#include "mdm.h"
#include <X11/Xlib.h>
#include "stb_ds.h"
static pid_t x_server;
static int got_usr1;
static Display* display;
Display* xdisplay;
pthread_t xthread;
pthread_mutex_t xmutex;
static void catch_usr1(int sig){
(void)sig;
got_usr1 = 1;
}
@ -34,25 +41,95 @@ int launch_x(void){
return 0;
}
void init_x(void){
XColor bg;
static int wm_detected = 0;
static int wm_detect(Display* disp, XErrorEvent* ev){
(void)disp;
(void)ev;
display = XOpenDisplay(NULL);
wm_detected = 1;
}
static void* x11_thread_routine(void* arg){
x_loop();
}
int init_x(void){
XColor bg;
void* old;
xdisplay = XOpenDisplay(NULL);
bg.red = 0x1c * 256;
bg.green = 0x45 * 256;
bg.blue = 0x73 * 256;
XAllocColor(display, DefaultColormap(display, DefaultScreen(display)), &bg);
XAllocColor(xdisplay, DefaultColormap(xdisplay, DefaultScreen(xdisplay)), &bg);
XSetWindowBackground(display, DefaultRootWindow(display), bg.pixel);
XClearWindow(display, DefaultRootWindow(display));
XFlush(display);
XSetWindowBackground(xdisplay, DefaultRootWindow(xdisplay), bg.pixel);
XClearWindow(xdisplay, DefaultRootWindow(xdisplay));
XFlush(xdisplay);
old = XSetErrorHandler(wm_detect);
XSelectInput(xdisplay, DefaultRootWindow(xdisplay), SubstructureRedirectMask);
XSync(xdisplay, False);
XSetErrorHandler(old);
if(wm_detected) return 1;
pthread_mutex_init(&xmutex, NULL);
pthread_create(&xthread, NULL, x11_thread_routine, NULL);
return 0;
}
int x_width(void){
return DisplayWidth(display, DefaultScreen(display));
return DisplayWidth(xdisplay, DefaultScreen(xdisplay));
}
int x_height(void){
return DisplayHeight(display, DefaultScreen(display));
return DisplayHeight(xdisplay, DefaultScreen(xdisplay));
}
typedef struct window {
MwWidget frame;
Window client;
} window_t;
void x_loop(void){
XEvent ev;
window_t* frames = NULL;
while(1){
XNextEvent(xdisplay, &ev);
if(ev.type == MapRequest){
XWindowAttributes xwa;
window_t w;
int i;
pthread_mutex_lock(&xmutex);
for(i = 0; i < arrlen(frames); i++){
if(frames[i].frame->lowlevel->x11.window == ev.xmaprequest.window){
XReparentWindow(xdisplay, frames[i].client, ev.xmaprequest.window, MwDefaultBorderWidth(root), MwDefaultBorderWidth(root));
XMapWindow(xdisplay, ev.xmaprequest.window);
XMapWindow(xdisplay, frames[i].client);
break;
}
}
if(i != arrlen(frames)){
pthread_mutex_unlock(&xmutex);
continue;
}
XGetWindowAttributes(xdisplay, ev.xmaprequest.window, &xwa);
w.client = ev.xmaprequest.window;
w.frame = MwVaCreateWidget(MwWindowClass, "frame", root, xwa.x - MwDefaultBorderWidth(root), xwa.y - MwDefaultBorderWidth(root), xwa.width + MwDefaultBorderWidth(root) * 2, xwa.height + MwDefaultBorderWidth(root) * 2,
MwNhasBorder, 1,
MwNinverted, 0,
NULL);
arrput(frames, w);
pthread_mutex_unlock(&xmutex);
}
}
}