diff options
author | beber <beber> | 2005-07-20 21:45:56 +0000 |
---|---|---|
committer | beber <beber> | 2005-07-20 21:45:56 +0000 |
commit | 5116a769391b039fcefab8a419600dff698fb2ac (patch) | |
tree | e36ee9107caa99d7643a5a963b0f7c8188c7efeb /event2.c | |
parent | new file (diff) | |
download | elock-5116a769391b039fcefab8a419600dff698fb2ac.tar.xz |
event2.c compil now works : Charset bug !!
Diffstat (limited to 'event2.c')
-rw-r--r-- | event2.c | 250 |
1 files changed, 118 insertions, 132 deletions
@@ -5,169 +5,155 @@ #include <X11/Xlib.h> #include <time.h> -typedef struct s_elock_win_item +typedef struct s_elock_win_item { - Window win; - time_t create_time; - t_elock_win_item *next; + Window win; + time_t create_time; + struct s_elock_win_item *next; } t_elock_win_item; typedef struct s_elock_win_list { - Display *disp; - t_elock_win_item *first; - t_elock_win_item *last; + Display *disp; + struct s_elock_win_item *first; + struct s_elock_win_item *last; } t_elock_win_list; -t_elock_win_list list; +t_elock_win_list list; -Display *elock_open_display(); -void elock_error (char *message); -void elock_echo(char *message); -t_elock_win_list *elock_init_list(Display *display); -static void elock_add_to_list(Window win); -static void elock_select_events ( Window wind, Bool substructureOnly); +Display *elock_open_display (); +void elock_error (char *message); +void elock_echo (char *message); +t_elock_win_list *elock_init_list (Display * display); +static void elock_add_to_list (Window win); +static void elock_select_events (Window wind, Bool substructureOnly); -Display *elock_open_display() +Display *elock_open_display () { - Display *disp; - - disp = XOpenDisplay(getenv("DISPLAY")); - - if ( disp == NULL) - { - fprintf (stderr, "Can't open Display\n"); - exit (1); - } - fprintf(stdout,"DISPLAY OPENED\n"); - - return disp; + Display *disp; + + disp = XOpenDisplay (getenv ("DISPLAY")); + + if (disp == NULL) + { + fprintf (stderr, "Can't open Display\n"); + exit (1); + } + fprintf (stdout, "DISPLAY OPENED\n"); + + return disp; } void elock_error (char *message) { - fprintf(stderr,"%s\n",message); - exit (1); + fprintf (stderr, "%s\n", message); + exit (1); } -void elock_echo(char *message) +void elock_echo (char *message) { - fprintf(stdout,"%s\n",message); - return; + fprintf (stdout, "%s\n", message); + return; } -t_elock_win_list *elock_init_list(Display *display) +t_elock_win_list *elock_init_list (Display * display) { - int loop; - t_elock_win_list list; - - list.disp = elock_open_display(); - list.first = 0; - list.last = 0; - - - for (loop = -1; ++loop < ScreenCount (display); ) - { - Window root = RootWindowOfScreen (ScreenOfDisplay (display, loop)); - elock_add_to_list (root); - elock_select_events (root, True); - } - t_elock_win_list *p_list = & list; - return p_list; + int loop; + t_elock_win_list list; + + list.disp = elock_open_display (); + list.first = 0; + list.last = 0; + + + for (loop = -1; ++loop < ScreenCount (display);) + { + Window root = RootWindowOfScreen (ScreenOfDisplay (display, loop)); + + elock_add_to_list (root); + elock_select_events (root, True); + } + t_elock_win_list *p_list = &list; + + return p_list; } -static void elock_add_to_list(Window win) +static void elock_add_to_list (Window win) { - t_elock_win_item *new_win_item = malloc (sizeof (t_elock_win_item)); - - if ( new_win_item == NULL) - elock_error("MALLOC ERROR"); - - new_win_item->win = win; - new_win_item->create_time = time(0); - new_win_item->next = 0; - - if ( ! list.first) - { - list.first = new_win_item; - } - if ( list.last) - { - list.last->next = new_win_item; - } - - list.last = new_win_item; + t_elock_win_item *new_win_item = malloc (sizeof (t_elock_win_item)); + + if (new_win_item == NULL) + elock_error ("MALLOC ERROR"); + + new_win_item->win = win; + new_win_item->create_time = time (0); + new_win_item->next = 0; + + if (!list.first) + { + list.first = new_win_item; + } + if (list.last) + { + list.last->next = new_win_item; + } + + list.last = new_win_item; } -static void elock_select_events ( Window wind, Bool substructureOnly) +static void elock_select_events (Window wind, Bool substructureOnly) { - Window elock_root; - Window elock_parent; - Window *elock_child; - unsigned elock_nb_child=0; - unsigned loop_count; - XWindowAttributes attribs; - - if (! XQueryTree(list.disp, - - wind, - &elock_root, - &elock_parent, - &elock_child, - &elock_nb_child)) - { - elock_error("XQueryTree ERROR"); - } - - if (elock_nb_child) - XFree ((char*) elock_child); - - if (substructureOnly) - XSelectInput (list.disp, wind, SubstructureNotifyMask); - else - { - if (elock_parent == None) - { - attribs.all_event_masks = - attribs.do_not_propagate_mask = KeyPressMask; - } - else if ( ! XGetWindowAttributes (list.disp, - wind, - &attribs)) - { - elock_error("XGetWindowAttributes ERROR"); - } - XSelectInput(list.disp, - wind, - SubstructureNotifyMask | - ((attribs.all_event_masks | - attribs.do_not_propagate_mask) - & KeyPressMask)); - } - - if (! XQueryTree(list.disp, - wind, - &elock_root, - &elock_parent, - &elock_child, - &elock_nb_child)) - { - elock_error("XQueryTree ERROR"); - } - - for (loop_count = 0 ; loop_count < elock_nb_child; ++loop_count) - { - elock_select_events (elock_child[loop_count], substructureOnly); - } - - if (elock_nb_child) - XFree ((char*) elock_child); + Window elock_root; + Window elock_parent; + Window *elock_child; + unsigned elock_nb_child = 0; + unsigned loop_count; + XWindowAttributes attribs; + + if (!XQueryTree (list.disp, wind, &elock_root, &elock_parent, &elock_child, &elock_nb_child)) + { + elock_error ("XQueryTree ERROR"); + } + + if (elock_nb_child) + XFree ((char *)elock_child); + + if (substructureOnly) + XSelectInput (list.disp, wind, SubstructureNotifyMask); + else + { + if (elock_parent == None) + { + attribs.all_event_masks = attribs.do_not_propagate_mask = KeyPressMask; + } + else if (!XGetWindowAttributes (list.disp, wind, &attribs)) + { + elock_error ("XGetWindowAttributes ERROR"); + } + XSelectInput (list.disp, + wind, + SubstructureNotifyMask | + ((attribs.all_event_masks | attribs.do_not_propagate_mask) & KeyPressMask)); + } + + if (!XQueryTree (list.disp, wind, &elock_root, &elock_parent, &elock_child, &elock_nb_child)) + { + elock_error ("XQueryTree ERROR"); + } + + for (loop_count = 0; loop_count < elock_nb_child; ++loop_count) + { + elock_select_events (elock_child[loop_count], substructureOnly); + } + + if (elock_nb_child) + XFree ((char *)elock_child); } int main () { - elock_init_list(elock_open_display()); + elock_init_list (elock_open_display ()); } |