redraw |= activate(widget);
if(widget != NULL) { redraw |= activate(widget); }
ctk_idle(void)     {  static ctk_arch_key_t c;  static unsigned char i;  register struct ctk_window *window;  register struct ctk_widget *widget;#if CTK_CONF_MOUSE_SUPPORT   static unsigned char mxc, myc, mouse_button_changed, mouse_moved,    mouse_clicked;  static unsigned char menux;  struct ctk_menu *menu;#endif /* CTK_CONF_MOUSE_SUPPORT */  #if CTK_CONF_MENUS  if(menus.open != NULL) {    maxnitems = menus.open->nitems;  } else {    maxnitems = 0;  }#endif /* CTK_CONF_MENUS */#if CTK_CONF_MOUSE_SUPPORT  mouse_button_changed = mouse_moved = mouse_clicked = 0;  /* See if there is any change in the buttons. */  if(ctk_mouse_button() != mouse_button) {    mouse_button = ctk_mouse_button();    mouse_button_changed = 1;    if(mouse_button == 0) {      mouse_clicked = 1;    }  }    /* Check if the mouse pointer has moved. */  if(ctk_mouse_x() != mouse_x ||     ctk_mouse_y() != mouse_y) {    mouse_x = ctk_mouse_x();    mouse_y = ctk_mouse_y();    mouse_moved = 1;  }  mxc = ctk_mouse_xtoc(mouse_x);  myc = ctk_mouse_ytoc(mouse_y); #endif /* CTK_CONF_MOUSE_SUPPORT */  if(mode == CTK_MODE_SCREENSAVER) {#ifdef CTK_SCREENSAVER_RUN    CTK_SCREENSAVER_RUN();#endif /* CTK_SCREENSAVER_RUN */    if(ctk_arch_keyavail()#if CTK_CONF_MOUSE_SUPPORT       || mouse_moved || mouse_button_changed#endif /* CTK_CONF_MOUSE_SUPPORT */       ) {      mode = CTK_MODE_NORMAL;      ctk_draw_init();      ctk_redraw();    }  } else if(mode == CTK_MODE_NORMAL) {#if CTK_CONF_MOUSE_SUPPORT     /* If there is any change in the mouse conditions, find out in       which window the mouse pointer currently is in order to send       the correct signals, or bring a window to focus. */    if(mouse_moved || mouse_button_changed) {      ctk_mouse_show();      screensaver_timer = 0;            if(myc == 0) {	/* Here we should do whatever needs to be done when the mouse	   moves around and clicks in the menubar. */	if(mouse_clicked) {	  /* Find out which menu that the mouse pointer is in. Start	     with the ->next menu after the desktop menu. We assume	     that the menus start one character from the left screen	     side and that the desktop menu is farthest to the	     right. */	  menux = 1;	  for(menu = menus.menus->next; menu != NULL; menu = menu->next) {	    if(mxc >= menux && mxc <= menux + menu->titlelen) {	      break;	    }	    menux += menu->titlelen;	  }	  	  /* Also check desktop menu. */	  if(mxc >= width - 7 &&	     mxc <= width - 1) {	    menu = &desktopmenu;	  }	  	  menus.open = menu;	  redraw |= REDRAW_MENUPART;	}      } else {	--myc;	if(menus.open != NULL) {	  /* Do whatever needs to be done when a menu is open. */	  if(menus.open == &desktopmenu) {	    menux = width - CTK_CONF_MENUWIDTH;	  } else {	    menux = 1;	    for(menu = menus.menus->next; menu != menus.open;		menu = menu->next) {	      menux += menu->titlelen;	    }	  }	  if(mxc >= menux && mxc <= menux + CTK_CONF_MENUWIDTH) {	    menus.open->active = myc;	  }	  	  if(mouse_clicked) {	    if(mxc >= menux && mxc <= menux + CTK_CONF_MENUWIDTH) {	      redraw |= activate_menu();	    } else {	      lastmenu = menus.open;	      menus.open = NULL;	      redraw |= REDRAW_MENUPART;	    }	  } else {	    redraw |= REDRAW_MENUS;	  	  }	} else {	  /* Walk through the windows from top to bottom to see in which	     window the mouse pointer is. */	  if(dialog != NULL) {	    window = dialog;	  } else {	  	 	  	    for(window = windows; window != NULL; window = window->next) {	      /* Check if the mouse is within the window. */	      if(mxc >= window->x &&		 mxc <= window->x + window->w &&		 myc >= window->y &&		 myc <= window->y + window->h) {		break;       		      }	    }	  }	  /* If we didn't find any window, and there are no windows	     open, the mouse pointer will definately be within the	     background desktop window. */	  if(window == NULL &&	     windows == NULL) {	    window = &desktop_window;	  }	  /* If the mouse pointer moves around outside of the currently	     focused window (or dialog), we should not have any focused	     widgets in the focused window so we make sure that there	     are none. */	  if(windows != NULL &&	     window != windows &&	     windows->focused != NULL){	  	    add_redrawwidget(windows->focused);	    windows->focused = NULL;	    redraw |= REDRAW_WIDGETS;	  }	  if(window != NULL) {	    /* If the mouse was clicked outside of the current window, we	       bring the clicked window to front. */	    if(dialog == NULL &&	       window != &desktop_window &&	   	       window != windows &&	       mouse_clicked) {	      /* Bring window to front. */	      ctk_window_open(window);	      redraw |= REDRAW_ALL;	    } else {	  	      /* Find out which widget currently is under the mouse pointer		 and give it focus, unless it already has focus. */	      mxc = mxc - window->x - 1;	      myc = myc - window->y - 1;      	    	      /* See if the mouse pointer is on a widget. If so, it should be		 selected and, if the button is clicked, activated. */	      for(widget = window->active; widget != NULL;		  widget = widget->next) {		if(mxc >= widget->x &&		   mxc <= widget->x + widget->w &&		   (myc == widget->y ||		    ((widget->type == CTK_WIDGET_BITMAP ||		      /*widget->type == CTK_WIDGET_TEXTMAP ||*/		      widget->type == CTK_WIDGET_ICON) &&		     (myc >= widget->y &&		      myc <= widget->y + ((struct ctk_bitmap *)widget)->h)))) {		  break;		}	      }	    	    	      if(mouse_moved) {		dispatcher_emit(ctk_signal_pointer_move, NULL,				window->owner);				if(window->focused != NULL &&		   widget != window->focused) {		  add_redrawwidget(window->focused);		  if(CTK_WIDGET_TYPE(window->focused) ==		     CTK_WIDGET_TEXTENTRY) {		    ((struct ctk_textentry *)(window->focused))->state =		      CTK_TEXTENTRY_NORMAL;		  }		  window->focused = NULL;		}		redraw |= REDRAW_WIDGETS;		if(widget != NULL) {		  select_widget(widget);		}	      }	    	      if(mouse_button_changed) {		dispatcher_emit(ctk_signal_pointer_button,				(ek_data_t)mouse_button,				window->owner);		if(mouse_clicked && widget != NULL) {		  select_widget(widget);		  redraw |= activate(widget);		}	      }	    }	  }    	}      }    }#endif /* CTK_CONF_MOUSE_SUPPORT */        while(ctk_arch_keyavail()) {      ctk_mouse_hide();            screensaver_timer = 0;            c = ctk_arch_getkey();                  if(dialog != NULL) {	window = dialog;      } else if(windows != NULL) {	window = windows;      } else {	window = &desktop_window;      }            widget = window->focused;	        if(widget != NULL &&	 widget->type == CTK_WIDGET_TEXTENTRY &&	 widget->widget.textentry.state == CTK_TEXTENTRY_EDIT) {	textentry_input(c, (struct ctk_textentry *)widget);	add_redrawwidget(widget);#if CTK_CONF_MENUS      } else if(menus.open != NULL) {	redraw |= menus_input(c);#endif /* CTK_CONF_MENUS */      } else {      	switch(c) {	case CH_CURS_RIGHT:	  switch_focus_widget(RIGHT);	  break;	case CH_CURS_DOWN:	  switch_focus_widget(DOWN);	  break;	case CH_CURS_LEFT:	  switch_focus_widget(LEFT);	  break;	case CH_CURS_UP:	  switch_focus_widget(UP);	  break;	case CH_ENTER:	  redraw |= activate(widget);	  break;#if CTK_CONF_MENUS	case CTK_CONF_MENU_KEY:	  if(dialog == NULL) {	    if(lastmenu == NULL) {	      menus.open = menus.menus;	    } else {	      menus.open = lastmenu;	    }	    menus.open->active = 0;	    redraw |= REDRAW_MENUS;	  } 	  break;#endif /* CTK_CONF_MENUS */	case CTK_CONF_WINDOWSWITCH_KEY:	  if(windows != NULL) {	    for(window = windows; window->next != NULL;		window = window->next);	    ctk_window_open(window);	    ctk_redraw();	  }	  break;	default:	  if(widget != NULL &&	     widget->type == CTK_WIDGET_TEXTENTRY) {	    widget->widget.textentry.state = CTK_TEXTENTRY_EDIT;	    textentry_input(c, (struct ctk_textentry *)widget);	    add_redrawwidget(widget);	  } else {	    dispatcher_emit(ctk_signal_keypress, (void *)c,			    window->owner);	  }	  break;	}      }      if(redraw & REDRAW_WIDGETS) {	for(i = 0; i < redraw_widgetptr; ++i) {	  ctk_widget_redraw(redraw_widgets[i]);	}	redraw &= ~REDRAW_WIDGETS;	redraw_widgetptr = 0;      }    }#if CTK_CONF_WINDOWMOVE  } else if(mode == CTK_MODE_WINDOWMOVE) {    redraw = 0;    window = windows;#if CTK_CONF_MOUSE_SUPPORT    /* If the mouse has moved, we move the window as well. */    if(mouse_moved) {      if(window->w + mxc + 2 >= width) {	window->x = width - 2 - window->w;      } else {	window->x = mxc;      }      if(window->h + myc + 2 >= height) {	window->y = height - 2 - window->h;      } else {	window->y = myc;      }      if(window->y > 0) {	--window->y;      }      redraw = REDRAW_ALL;    }		          /* Check if the mouse has been clicked, and stop moving the window       if so. */    if(mouse_button_changed &&       mouse_button == 0) {      mode = CTK_MODE_NORMAL;      redraw = REDRAW_ALL;          }#endif /* CTK_CONF_MOUSE_SUPPORT */        while(mode == CTK_MODE_WINDOWMOVE && ctk_arch_keyavail()) {          screensaver_timer = 0;            c = ctk_arch_getkey();            switch(c) {      case CH_CURS_RIGHT:	++window->x;	if(window->x + window->w + 1 >= width) {	  --window->x;	}	redraw = REDRAW_ALL;	break;      case CH_CURS_LEFT:	if(window->x > 0) {	  --window->x;	}	redraw = REDRAW_ALL;	break;      case CH_CURS_DOWN:	++window->y;	if(window->y + window->h + 2 >= height) {	  --window->y;	}	redraw = REDRAW_ALL;	break;      case CH_CURS_UP:	if(window->y > 0) {	  --window->y;	}	redraw = REDRAW_ALL;	break;      case CH_ENTER:      case CH_ESC:	mode = CTK_MODE_NORMAL;	redraw = REDRAW_ALL;	break;      }    }    /*    if(redraw & REDRAW_ALL) {      do_redraw_all(1, height);    }    redraw = 0;*/#endif /* CTK_CONF_WINDOWMOVE */  }  if(redraw & REDRAW_ALL) {    do_redraw_all(1, height);#if CTK_CONF_MENUS  } else if(redraw & REDRAW_MENUPART) {    do_redraw_all(1, maxnitems + 1);  } else if(redraw & REDRAW_MENUS) {    ctk_draw_menus(&menus);#endif /* CTK_CONF_MENUS */  } else if(redraw & REDRAW_FOCUS) {    if(dialog != NULL) {      ctk_window_redraw(dialog);    } else if(windows != NULL) {      ctk_window_redraw(windows);	    } else {      ctk_window_redraw(&desktop_window);	    }  } else if(redraw & REDRAW_WIDGETS) {    for(i = 0; i < redraw_widgetptr; ++i) {      ctk_widget_redraw(redraw_widgets[i]);    }  }      redraw = 0;  redraw_widgetptr = 0;  }