This commit is contained in:
Nishi 2025-11-16 08:26:47 +09:00
commit 45a24f90b9
Signed by: nishi
GPG key ID: 27EF69B208EB9343
5 changed files with 152 additions and 2 deletions

View file

@ -2,6 +2,9 @@ project(
mdm
)
find_package(PkgConfig)
pkg_check_modules(X11 REQUIRED x11)
file(
GLOB
mdm_SRC
@ -13,10 +16,22 @@ add_executable(
${mdm_SRC}
)
target_include_directories(
mdm
PRIVATE
${X11_INCLUDE_DIRS}
)
target_link_directories(
mdm
PRIVATE
${X11_LIBRARY_DIRS}
)
target_link_libraries(
mdm
PRIVATE
MDELib
${X11_LIBRARIES} MDELib Mw
)
include(GNUInstallDirs)

29
mdm/login.c Normal file
View file

@ -0,0 +1,29 @@
#include "mdm.h"
#include <Mw/Milsko.h>
void make_login_window(void){
MwWidget w, pic, userlabel, usercombo, passlabel, passentry;
MwLibraryInit();
w = MwVaCreateWidget(MwWindowClass, "login", NULL, (x_width() - 366) / 2, (x_height() - 183) / 2, 366, 183,
MwNhasBorder, 1,
MwNinverted, 0,
NULL);
pic = MwVaCreateWidget(MwImageClass, "image", w, 10, 10, 80, 137,
MwNhasBorder, 1,
NULL);
userlabel = MwVaCreateWidget(MwLabelClass, "userlabel", w, 95, 10, MwTextWidth(w, "User:"), 16,
MwNtext, "User:",
NULL);
usercombo = MwCreateWidget(MwComboBoxClass, "usercombo", w, 95, 10+16+5, 265, 18);
passlabel = MwVaCreateWidget(MwLabelClass, "passlabel", w, 95, 10+16+5+18+5, MwTextWidth(w, "Password:"), 16,
MwNtext, "Password:",
NULL);
passentry = MwVaCreateWidget(MwEntryClass, "passentry", w, 95, 10+16+5+18+5+16+5, 265, 18,
MwNhideInput, 1,
NULL);
MwLoop(w);
}

View file

@ -1 +1,29 @@
int main(){}
#include "mdm.h"
#include <stdio.h>
#include <string.h>
int is_launch_x = 1;
int main(int argc, char** argv){
int i, st;
for(i = 1; i < argc; i++){
if(argv[i][0] == '-'){
if(strcmp(argv[i], "-X") == 0 || strcmp(argv[i], "--no-launch-x") == 0){
is_launch_x = 0;
}else{
fprintf(stderr, "%s: bad option: %s\n", argv[0], argv[i]);
return 1;
}
}
}
if(is_launch_x){
if((st = launch_x()) != 0) return st;
}
init_x();
make_login_window();
}

11
mdm/mdm.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef __MDM_H__
#define __MDM_H__
int launch_x(void);
int x_width(void);
int x_height(void);
void init_x(void);
void make_login_window(void);
#endif

67
mdm/xserver.c Normal file
View file

@ -0,0 +1,67 @@
#include "mdm.h"
#include <X11/Xlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <signal.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
static pid_t x_server;
static int got_usr1;
static Display* display;
static void catch_usr1(int sig){
got_usr1 = 1;
}
int launch_x(void){
got_usr1 = 0;
signal(SIGUSR1, catch_usr1);
if((x_server = fork()) == 0){
signal(SIGUSR1, SIG_IGN);
execlp("X", "X", ":0", NULL);
_exit(-1);
}else{
while(!got_usr1){
if(waitpid(x_server, NULL, WNOHANG) != 0){
fprintf(stderr, "server died. what happened?\n");
return 1;
}
usleep(1000);
}
}
setenv("DISPLAY", ":0", 1);
return 0;
}
void init_x(void){
XColor bg;
display = XOpenDisplay(NULL);
bg.red = 0x1c * 256;
bg.green = 0x45 * 256;
bg.blue = 0x73 * 256;
XAllocColor(display, DefaultColormap(display, DefaultScreen(display)), &bg);
XSetWindowBackground(display, DefaultRootWindow(display), bg.pixel);
XClearWindow(display, DefaultRootWindow(display));
XFlush(display);
}
int x_width(void){
return DisplayWidth(display, DefaultScreen(display));
}
int x_height(void){
return DisplayHeight(display, DefaultScreen(display));
}