wm

My window manager
git clone git://pcardenasb.com/wm
Log | Files | Refs

commit c4f29d7e5b714b388dab0e437f9ddddcc86c7f80
parent 15d58b14d210f2f7f9d5f81b4fea97ce4bc9ef09
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Mon, 30 Dec 2024 16:42:09 -0500

Refactoring to array when event defaults

Diffstat:
Mpwm.c | 108++++++++++++++++++++++++++++---------------------------------------------------
1 file changed, 38 insertions(+), 70 deletions(-)

diff --git a/pwm.c b/pwm.c @@ -287,76 +287,44 @@ int main(void) break; default: fprintf(stderr, "ev.type = %2d ", ev.type); - if (ev.type == 2) - fprintf(stderr, "= KeyPress\n"); - if (ev.type == 3) - fprintf(stderr, "= KeyRelease\n"); - if (ev.type == 4) - fprintf(stderr, "= ButtonPress\n"); - if (ev.type == 5) - fprintf(stderr, "= ButtonRelease\n"); - if (ev.type == 6) - fprintf(stderr, "= MotionNotify\n"); - if (ev.type == 7) - fprintf(stderr, "= EnterNotify\n"); - if (ev.type == 8) - fprintf(stderr, "= LeaveNotify\n"); - if (ev.type == 9) - fprintf(stderr, "= FocusIn\n"); - if (ev.type == 10) - fprintf(stderr, "= FocusOut\n"); - if (ev.type == 11) - fprintf(stderr, "= KeymapNotify\n"); - if (ev.type == 12) - fprintf(stderr, "= Expose\n"); - if (ev.type == 13) - fprintf(stderr, "= GraphicsExpose\n"); - if (ev.type == 14) - fprintf(stderr, "= NoExpose\n"); - if (ev.type == 15) - fprintf(stderr, "= VisibilityNotify\n"); - if (ev.type == 16) - fprintf(stderr, "= CreateNotify\n"); - if (ev.type == 17) - fprintf(stderr, "= DestroyNotify\n"); - if (ev.type == 18) - fprintf(stderr, "= UnmapNotify\n"); - if (ev.type == 19) - fprintf(stderr, "= MapNotify\n"); - if (ev.type == 20) - fprintf(stderr, "= MapRequest\n"); - if (ev.type == 21) - fprintf(stderr, "= ReparentNotify\n"); - if (ev.type == 22) - fprintf(stderr, "= ConfigureNotify\n"); - if (ev.type == 23) - fprintf(stderr, "= ConfigureRequest\n"); - if (ev.type == 24) - fprintf(stderr, "= GravityNotify\n"); - if (ev.type == 25) - fprintf(stderr, "= ResizeRequest\n"); - if (ev.type == 26) - fprintf(stderr, "= CirculateNotify\n"); - if (ev.type == 27) - fprintf(stderr, "= CirculateRequest\n"); - if (ev.type == 28) - fprintf(stderr, "= PropertyNotify\n"); - if (ev.type == 29) - fprintf(stderr, "= SelectionClear\n"); - if (ev.type == 30) - fprintf(stderr, "= SelectionRequest\n"); - if (ev.type == 31) - fprintf(stderr, "= SelectionNotify\n"); - if (ev.type == 32) - fprintf(stderr, "= ColormapNotify\n"); - if (ev.type == 33) - fprintf(stderr, "= ClientMessage\n"); - if (ev.type == 34) - fprintf(stderr, "= MappingNotify\n"); - if (ev.type == 35) - fprintf(stderr, "= GenericEvent\n"); - if (ev.type == 36) - fprintf(stderr, "= LASTEvent\n"); + char events[LASTEvent + 1][19] = { + [2] = "KeyPress", + [3] = "KeyRelease", + [4] = "ButtonPress", + [5] = "ButtonRelease", + [6] = "MotionNotify", + [7] = "EnterNotify", + [8] = "LeaveNotify", + [9] = "FocusIn", + [10] = "FocusOut", + [11] = "KeymapNotify", + [12] = "Expose", + [13] = "GraphicsExpose", + [14] = "NoExpose", + [15] = "VisibilityNotify", + [16] = "CreateNotify", + [17] = "DestroyNotify", + [18] = "UnmapNotify", + [19] = "MapNotify", + [20] = "MapRequest", + [21] = "ReparentNotify", + [22] = "ConfigureNotify", + [23] = "ConfigureRequest", + [24] = "GravityNotify", + [25] = "ResizeRequest", + [26] = "CirculateNotify", + [27] = "CirculateRequest", + [28] = "PropertyNotify", + [29] = "SelectionClear", + [30] = "SelectionRequest", + [31] = "SelectionNotify", + [32] = "ColormapNotify", + [33] = "ClientMessage", + [34] = "MappingNotify", + [35] = "GenericEvent", + [36] = "LASTEvent", + }; + fprintf(stderr, "= %s\n", events[ev.type]); } } }