浏览代码

Small refactorings

master
Bert 13 年前
父节点
当前提交
45b2b45285
共有 3 个文件被更改,包括 15 次插入9 次删除
  1. +1
    -1
      app.c
  2. +2
    -2
      events.c
  3. +12
    -6
      window.c

+ 1
- 1
app.c 查看文件

@@ -22,7 +22,7 @@
#include "app.h" #include "app.h"


void app_init(app_t *app) { void app_init(app_t *app) {
if (app == NULL)
if (!app)
return; return;


app->fileidx = 0; app->fileidx = 0;


+ 2
- 2
events.c 查看文件

@@ -30,7 +30,7 @@ void on_expose(app_t *app, XEvent *ev) {
} }


void on_configurenotify(app_t *app, XEvent *ev) { void on_configurenotify(app_t *app, XEvent *ev) {
if (app == NULL || ev == NULL)
if (!app || !ev)
return; return;
win_configure(&app->win, &ev->xconfigure); win_configure(&app->win, &ev->xconfigure);
@@ -40,7 +40,7 @@ void on_keypress(app_t *app, XEvent *ev) {
KeySym keysym; KeySym keysym;
XKeyEvent *kev; XKeyEvent *kev;


if (app == NULL || ev == NULL)
if (!app || !ev)
return; return;
kev = &ev->xkey; kev = &ev->xkey;


+ 12
- 6
window.c 查看文件

@@ -27,6 +27,9 @@
Display *dpy; Display *dpy;
int scr; int scr;
int scrw, scrh; int scrw, scrh;
Visual *vis;
Colormap cmap;
int depth;
GC gc; GC gc;
XColor bgcol; XColor bgcol;


@@ -35,7 +38,7 @@ void win_open(win_t *win) {
XSetWindowAttributes attr; XSetWindowAttributes attr;
unsigned long mask; unsigned long mask;


if (win == NULL)
if (!win)
return; return;


if (!(dpy = XOpenDisplay(NULL))) if (!(dpy = XOpenDisplay(NULL)))
@@ -45,6 +48,10 @@ void win_open(win_t *win) {
scrw = DisplayWidth(dpy, scr); scrw = DisplayWidth(dpy, scr);
scrh = DisplayHeight(dpy, scr); scrh = DisplayHeight(dpy, scr);


vis = DefaultVisual(dpy, scr);
cmap = DefaultColormap(dpy, scr);
depth = DefaultDepth(dpy, scr);

if (!XAllocNamedColor(dpy, DefaultColormap(dpy, scr), BG_COLOR, if (!XAllocNamedColor(dpy, DefaultColormap(dpy, scr), BG_COLOR,
&bgcol, &bgcol)) &bgcol, &bgcol))
FATAL("could not allocate color: %s", BG_COLOR); FATAL("could not allocate color: %s", BG_COLOR);
@@ -61,9 +68,8 @@ void win_open(win_t *win) {
attr.save_under = False; attr.save_under = False;
mask = CWBackingStore | CWBackPixel | CWSaveUnder; mask = CWBackingStore | CWBackPixel | CWSaveUnder;


win->xwin = XCreateWindow(dpy, RootWindow(dpy, scr),
win->x, win->y, win->w, win->h, 0, DefaultDepth(dpy, scr), InputOutput,
DefaultVisual(dpy, scr), mask, &attr);
win->xwin = XCreateWindow(dpy, RootWindow(dpy, scr), win->x, win->y,
win->w, win->h, 0, depth, InputOutput, vis, mask, &attr);
if (win->xwin == None) if (win->xwin == None)
FATAL("could not create window"); FATAL("could not create window");
@@ -84,7 +90,7 @@ void win_open(win_t *win) {
} }


void win_close(win_t *win) { void win_close(win_t *win) {
if (win == NULL)
if (!win)
return; return;


XDestroyWindow(dpy, win->xwin); XDestroyWindow(dpy, win->xwin);
@@ -95,7 +101,7 @@ void win_close(win_t *win) {
int win_configure(win_t *win, XConfigureEvent *cev) { int win_configure(win_t *win, XConfigureEvent *cev) {
int changed; int changed;


if (win == NULL)
if (!win)
return 0; return 0;
changed = win->x != cev->x || win->y != cev->y || changed = win->x != cev->x || win->y != cev->y ||


正在加载...
取消
保存