コード例 #1
0
ファイル: vwm_menu.c プロジェクト: notbryant/Neckbear-de-
gint vwm_main_menu_ON_KEYSTROKE(gint32 keystroke,WINDOW *window)
{
	MENU			*menu=NULL;
	MEVENT		mevent;
	gchar			*item_text=NULL;
	WINDOW		*new_window;
	VWM_MODULE	*vwm_module;

	menu=(MENU*)viper_window_get_userptr(window);
   if(keystroke==-1) return 1;

   viper_thread_enter();

	if(keystroke==KEY_MOUSE)
	{
		menu_driver(menu,keystroke);
      vwm_menu_marshall(menu,REQ_DOWN_ITEM);
		getmouse(&mevent);
		if(mevent.bstate & BUTTON1_DOUBLE_CLICKED) keystroke=KEY_CRLF;
      else
      {
         viper_window_redraw(window);
         viper_thread_leave();
         return 1;
      }
	}

   if(keystroke=='s')
   {
      viper_thread_enter();
/*      new_window=viper_filedlg_create(window," Pick a file... ",0.5,0.5,0.5,0.5,
         NULL,FILEDLG_VIEW_EXTENDED); */
/*      new_window=viper_filedlg_create(window," Pick a file... ",0.5,0.5,0.5,0.5,
         NULL,FILEDLG_VIEW_BASIC | FILEDLG_SHOW_CTIME); */
      new_window=viper_filedlg_create(window," Pick a file... ",
			0.5,0.5,0.8,0.5,NULL,FILEDLG_FULL);
      viper_window_set_top(new_window);
      viper_thread_leave();
   }

	if(keystroke==KEY_UP)
   {
      menu_driver(menu,REQ_UP_ITEM);
      vwm_menu_marshall(menu,REQ_UP_ITEM);
   }
	if(keystroke==KEY_DOWN)
   {
      menu_driver(menu,REQ_DOWN_ITEM);
      vwm_menu_marshall(menu,REQ_DOWN_ITEM);
   }

	if(keystroke==KEY_CRLF)
	{
      item_text=(gchar*)item_name(current_item(menu));
		vwm_module=vwm_module_find(&item_text[2]);
		if(vwm_module!=NULL)
		{
			new_window=vwm_module->mod_main(vwm_module->anything);
         viper_window_close(window);
			if(new_window!=NULL) viper_window_set_top(new_window);
			viper_thread_leave();
			return 1;
		}
	}
	
	viper_window_redraw(window);
	viper_thread_leave();
	return 1;
}
コード例 #2
0
ファイル: vwm_menu.c プロジェクト: notbryant/Neckbear-de-
WINDOW* vwm_main_menu(void)
{
   extern WINDOW  *SCREEN_WINDOW;
	MENU           *menu=NULL;
	WINDOW 		   *window;
	gint			   width=0,height=0;
   gint           screen_height;

	VWM_MODULE	   *vwm_module;
	GSList		   *category_list=NULL;
	GSList		   *module_list=NULL;
	GSList		   *node1;
	GSList		   *node2;

	gchar			   **item_list;
   gint           idx=0;

   /* allocate storage for 128 menu items    */
   item_list=(gchar**)g_malloc0(sizeof(gchar*)*(MAX_MENU_ITEMS+1));

   item_list[idx]=g_strdup_printf(" ");
   idx++;
	category_list=vwm_modules_list_categories();
   node1=category_list;
   while(node1!=NULL && idx<MAX_MENU_ITEMS)
   {
      /* skip screensavers */
      if(strcmp((gchar*)node1->data,VWM_SCREENSAVER)==0)
      {
         node1=node1->next;
         continue;
      }

      /* add the category  */
      item_list[idx]=g_strdup_printf("%s",(gchar*)node1->data);
      idx++;
      if(idx==MAX_MENU_ITEMS) break;

      module_list=vwm_modules_list((gchar*)node1->data);
      node2=module_list;
      while(node2!=NULL)
      {
         if(idx==MAX_MENU_ITEMS) break;
         vwm_module=(VWM_MODULE*)node2->data;
         item_list[idx]=g_strdup_printf("..%s",vwm_module->title);
         idx++;
         node2=node2->next;
      }

      /* add a space before the next menu category  */
      if(idx<MAX_MENU_ITEMS)
      {
         item_list[idx]=g_strdup_printf(" ");
         idx++;
      }

      if(module_list!=NULL) g_slist_free(module_list);
      node1=node1->next;
   }
   if(category_list!=NULL) g_slist_free(category_list);

   menu=viper_menu_create(item_list);
   while(idx!=-1)
   {
      g_free(item_list[idx]);
      idx--;
   }
   g_free(item_list);

	/* hide character mark on left hand side */
	set_menu_mark(menu," ");

   window_get_size_scaled(SCREEN_WINDOW,NULL,&screen_height,0,0.80);

	scale_menu(menu,&height,&width);
	width++;
	if(width<16) width=16;
 	/* override the default of 1 column X 16 entries per row */
   if(height>(screen_height-4)) height=screen_height-4;
	set_menu_format(menu,height,1);

	viper_thread_enter();
	window=viper_window_create(" Menu ",1,2,width,height,TRUE);
   /* todo:  it would be nice if the user could resize the window (especially
      in the horizonal direction) and add more columns to the display.  right
      now, it's not a priority (but it would be easy to implement).  just need
      a few lines of code for the event window-resized.  for now, just don't
      allow it */
	set_menu_win(menu,window);
	set_menu_fore(menu,VIPER_COLORS(COLOR_WHITE,COLOR_BLUE) | A_BOLD);
	set_menu_back(menu,VIPER_COLORS(COLOR_BLACK,COLOR_WHITE));
	menu_opts_off(menu,O_NONCYCLIC);
	post_menu(menu);
   vwm_menu_marshall(menu,REQ_DOWN_ITEM);

	/* viper_event_set(window,"window-activate",vwm_main_menu_ON_ACTIVATE,NULL); */
	viper_event_set(window,"window-close",vwm_main_menu_ON_CLOSE,
		(gpointer)menu);
	viper_window_set_key_func(window,vwm_main_menu_ON_KEYSTROKE);
	viper_window_set_userptr(window,(gpointer)menu);

	viper_thread_leave();
	return window;
}
コード例 #3
0
ファイル: mainmenu.c プロジェクト: TragicWarrior/vwm
WINDOW* vwm_main_menu(void)
{
    extern WINDOW   *SCREEN_WINDOW;
	MENU            *menu = NULL;
	WINDOW 		    *window;
	int			    width = 0,height = 0;
    int             screen_height;

	vwm_module_t	*vwm_module;
    char            buf[NAME_MAX];

    gchar			**item_list;
    int             idx = 0;
    int             i;

    // allocate storage for a total of MAX_MENU_ITEMS
    item_list = (gchar**)g_malloc0(sizeof(gchar*) * (MAX_MENU_ITEMS + 1));

    item_list[idx] = g_strdup_printf(" ");
    idx++;

    // iterate through the categories defined in modules.def
    for(i = 0;i < VWM_MOD_TYPE_MAX;i++)
    {
        // skip screensaver type modules.  they are a special class.
        if(i == VWM_MOD_TYPE_SCREENSAVER) continue;

        // print the menu category (type) to the window
        item_list[idx] = g_strdup_printf("%s",modtype_desc[i]);
        idx++;

        vwm_module = NULL;

        do
        {
            if(idx == MAX_MENU_ITEMS) break;

            vwm_module = vwm_module_find_by_type(vwm_module,i);
            if(vwm_module == NULL) break;

            vwm_module_get_title(vwm_module,buf,sizeof(buf) - 1);
            item_list[idx] = g_strdup_printf("..%s",buf);
            idx++;
        }
        while(vwm_module != NULL);

        // add a space before the next menu category
        if(idx < MAX_MENU_ITEMS)
        {
            item_list[idx] = g_strdup_printf(" ");
            idx++;
        }
    }

    menu = viper_menu_create(item_list);
    while(idx != -1)
    {
        g_free(item_list[idx]);
        idx--;
    }
    g_free(item_list);

	// hide character mark on left hand side
	set_menu_mark(menu," ");

    window_get_size_scaled(SCREEN_WINDOW,NULL,&screen_height,0,0.80);

	scale_menu(menu,&height,&width);
	width++;
	if(width < 16) width = 16;

 	// override the default of 1 column X 16 entries per row
    if(height>(screen_height-4)) height=screen_height-4;
	set_menu_format(menu,height,1);

	viper_thread_enter();
	window = viper_window_create(" Menu ",1,2,width,height,TRUE);
    /*
        todo:   it would be nice if the user could resize the menu
                (especially in the horizonal direction) and add more
                columns to the display.  right now, it's not a priority
                (but it would be easy to implement).  just need a few
                lines of code for the event window-resized.  for now,
                just don't allow it
    */
	set_menu_win(menu,window);
	set_menu_fore(menu,VIPER_COLORS(COLOR_WHITE,COLOR_BLUE) | A_BOLD);
	set_menu_back(menu,VIPER_COLORS(COLOR_BLACK,COLOR_WHITE));
	menu_opts_off(menu,O_NONCYCLIC);
	post_menu(menu);
    vwm_menu_marshall(menu,REQ_DOWN_ITEM);

	/* viper_event_set(window,"window-activate",vwm_main_menu_ON_ACTIVATE,NULL); */
	viper_event_set(window,"window-close",vwm_main_menu_ON_CLOSE,
		(gpointer)menu);
	viper_window_set_key_func(window,vwm_main_menu_ON_KEYSTROKE);
	viper_window_set_userptr(window,(gpointer)menu);

	viper_thread_leave();
	return window;
}