clean up main function more
This commit is contained in:
parent
96b82dc223
commit
b97847c207
|
@ -15,6 +15,37 @@ void prepare_window_size(void) {
|
|||
return;
|
||||
}
|
||||
|
||||
void store_image_vars(void) {
|
||||
#if USEIMAGE
|
||||
longestedge = MAX(imagewidth, imageheight);
|
||||
|
||||
if (!imagew || !imageh || !imageg) {
|
||||
imagew = imagewidth;
|
||||
imageh = imageheight;
|
||||
imagegaps = imagegaps;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_mode(void) {
|
||||
if (!type) { // no typing allowed, require normal mode
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
// set default mode, must be done before the event loop or keybindings will not work
|
||||
if (mode) {
|
||||
curMode = 1;
|
||||
allowkeys = 1;
|
||||
|
||||
strcpy(modetext, instext);
|
||||
} else {
|
||||
curMode = 0;
|
||||
allowkeys = !curMode;
|
||||
|
||||
strcpy(modetext, normtext);
|
||||
}
|
||||
}
|
||||
|
||||
void get_width(int numwidthchecks, unsigned int minstrlen, unsigned int curstrlen) {
|
||||
struct item *item;
|
||||
unsigned int tmp = 0;
|
||||
|
|
|
@ -6,3 +6,5 @@ static void prepare_window_size(void);
|
|||
static void set_window(void);
|
||||
static void set_prop(void);
|
||||
static void resizeclient(void);
|
||||
static void store_image_vars(void);
|
||||
static void set_mode(void);
|
||||
|
|
|
@ -147,3 +147,30 @@ void set_screen(Display *disp) {
|
|||
screen = DefaultScreen(disp);
|
||||
root = RootWindow(disp, screen);
|
||||
}
|
||||
|
||||
void handle_x11(void) {
|
||||
XWindowAttributes wa;
|
||||
|
||||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||
fputs("warning: no locale support\n", stderr); // invalid locale, so notify the user about it
|
||||
|
||||
if (!XSetLocaleModifiers(""))
|
||||
fputs("warning: no locale modifiers support\n", stderr);
|
||||
|
||||
if (!(dpy = opendisplay(NULL)))
|
||||
die("spmenu: cannot open display"); // failed to open display
|
||||
|
||||
// set screen and root window
|
||||
set_screen(dpy);
|
||||
|
||||
// parent window is the root window (ie. window manager) because we're not embedding
|
||||
if (!embed || !(parentwin = strtol(embed, NULL, 0)))
|
||||
parentwin = root;
|
||||
|
||||
if (!XGetWindowAttributes(dpy, parentwin, &wa)) {
|
||||
die("spmenu: could not get embedding window attributes: 0x%lx", parentwin);
|
||||
}
|
||||
|
||||
xinitvisual(); // init visual and create drawable after
|
||||
drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
|
||||
}
|
||||
|
|
|
@ -6,4 +6,5 @@ static Window root, parentwin, win;
|
|||
|
||||
static void setupdisplay(void);
|
||||
static void set_screen(Display *disp);
|
||||
static void handle_x11(void);
|
||||
static Display * opendisplay(char *disp);
|
||||
|
|
61
spmenu.c
61
spmenu.c
|
@ -509,62 +509,15 @@ void xinitvisual(void) {
|
|||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
XWindowAttributes wa;
|
||||
|
||||
readargs(argc, argv); // start by reading arguments
|
||||
|
||||
#if USEIMAGE
|
||||
longestedge = MAX(imagewidth, imageheight);
|
||||
#endif
|
||||
|
||||
if (!type) {
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
// set default mode, must be done before the event loop or keybindings will not work
|
||||
if (mode) {
|
||||
curMode = 1;
|
||||
allowkeys = 1;
|
||||
|
||||
strcpy(modetext, instext);
|
||||
} else {
|
||||
curMode = 0;
|
||||
allowkeys = !curMode;
|
||||
|
||||
strcpy(modetext, normtext);
|
||||
}
|
||||
|
||||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||
fputs("warning: no locale support\n", stderr); // invalid locale, so notify the user about it
|
||||
|
||||
if (!XSetLocaleModifiers(""))
|
||||
fputs("warning: no locale modifiers support\n", stderr);
|
||||
|
||||
if (!(dpy = opendisplay(NULL)))
|
||||
die("spmenu: cannot open display"); // failed to open display
|
||||
|
||||
// set screen and root window
|
||||
set_screen(dpy);
|
||||
|
||||
// parent window is the root window (ie. window manager) because we're not embedding
|
||||
if (!embed || !(parentwin = strtol(embed, NULL, 0)))
|
||||
parentwin = root;
|
||||
|
||||
if (!XGetWindowAttributes(dpy, parentwin, &wa)) {
|
||||
die("spmenu: could not get embedding window attributes: 0x%lx", parentwin);
|
||||
}
|
||||
|
||||
xinitvisual(); // init visual and create drawable after
|
||||
drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap); // wrapper function creating a drawable
|
||||
// open x11 display and create drawable
|
||||
handle_x11();
|
||||
|
||||
// load fonts
|
||||
if (!drw_font_create(drw, fonts, LENGTH(fonts)))
|
||||
die("no fonts could be loaded.");
|
||||
|
||||
// resize window
|
||||
lrpad = drw->font->h + textpadding;
|
||||
prepare_window_size(); // this function sets padding size
|
||||
|
||||
// pledge limits what programs can do, so here we specify what spmenu should be allowed to do
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio rpath wpath cpath", NULL) == -1)
|
||||
|
@ -582,14 +535,8 @@ int main(int argc, char *argv[]) {
|
|||
grabkeyboard();
|
||||
}
|
||||
|
||||
// set default values
|
||||
#if USEIMAGE
|
||||
if (!imagew || !imageh || !imageg) {
|
||||
imagew = imagewidth;
|
||||
imageh = imageheight;
|
||||
imagegaps = imagegaps;
|
||||
}
|
||||
#endif
|
||||
store_image_vars();
|
||||
set_mode();
|
||||
|
||||
init_appearance(); // init colorschemes by reading arrays
|
||||
setupdisplay(); // set up display and create window
|
||||
|
|
Loading…
Reference in a new issue