From romano@sensores2.fis.ucm.es Tue Nov 16 12:48:36 1993
Return-Path: <romano@sensores2.fis.ucm.es>
Received: from eagle.is.lmsc.lockheed.com (eagle.lockheed.com) by rocket (4.1/SMI-4.1)
	id AA07376; Tue, 16 Nov 93 12:48:29 EST
Received: by eagle.is.lmsc.lockheed.com (5.57/Ultrix-4.2)
	id AA04974; Tue, 16 Nov 93 09:49:37 -0800
Received: by sensores2.fis.ucm.es (Linux Smail3.1.28.1 #14)
	id m0ozVPx-000AuzC; Tue, 16 Nov 93 18:46 GMT
Message-Id: <m0ozVPx-000AuzC@sensores2.fis.ucm.es>
From: romano@sensores2.fis.ucm.es (Romano Giannetti)
Subject: (Again) a little fvwm patch to add DIRMENU
To: nation@rocket.sanders.lockheed.com
Date: Tue, 16 Nov 1993 18:46:19 +0000 (GMT)
X-Mailer: ELM [version 2.4 PL21]
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 11794     
Reply-To: romano@pimac2.iet.unipi.it
Status: RO


Hola... :)

  	Sorry for send you this once again, but I have cleaned up a
little my dir_exec patch to fvwm1.05. (It was the first time to me
doing a "diff -c" and I did it quite wrong the first time). 
	Old message with new patch following...

Hi.

	First of all I have to say that your fvwm is really a
wonderful window manager, and it is written in a style and with a
clarity that make me understand the difference between a professional
programmer and ...me.

	Now the point. I have written that little patch that mimic the
"DIRMENU" option in openwin. This is very useful to me: having users
that are _very_ newbie in Unix, I can create three or four directories
(for example /xmenus/editors, /xmenus/networks, etc) and put slink to
the real program, then changes for all the users (included that ones
with a private .fvwmrc) is fast and reliable. (I hope :).

	I have tried it a little. The only problem I see is that it
will be a Good Thing add a "scroll bar" or somehing like it to
MakeMenu when the menu is _very_ long... but this is a too long
work for me (now).

	If there are no problem for you, I will post these patch on 
USENET next week (or if you like, you can post them...).

	The last thing: in the Imakefile there was a little bug
(fvwm1.05), just a */ in the wrong position.

	Bye,
		Romano.


**********snip snip snip ***************

diff -c --ignore-blank-lines --ignore-space-change --new-file --recursive fvwm.orig/Imakefile fvwm/Imakefile
*** fvwm.orig/Imakefile	Wed Nov 10 20:16:14 1993
--- fvwm/Imakefile	Tue Nov 16 11:41:16 1993
***************
*** 63,75 ****
   *
   * NO_PAGER - Omits the code for the pager
   * NON_VIRTUAL - Omits the virtual desktop - requires NO_PAGER
!  * NO_ICONS - Omits icon drawing (You have the use the window list) */
   * NO_SAVEUNDERS - tells thw WM not to request save unders for pop-up
   *                 menus. A quick test using monochrome X11 shows that save
   *                 unders cost about 4Kbytes RAM, but saves a lot of
   *                 window re-draws if you have windows that take a while
   *                 to refresh. For xcolor, I assume the cost is more like
!  *                 4Kbytesx8 = 32kbytes (256 color).
  
  /*EF1 = -DNO_PAGER -DNON_VIRTUAL  -DNO_ICONS -DNO_SAVEUNDERS/**/
  
--- 63,75 ----
   *
   * NO_PAGER - Omits the code for the pager
   * NON_VIRTUAL - Omits the virtual desktop - requires NO_PAGER
!  * NO_ICONS - Omits icon drawing (You have the use the window list) 
   * NO_SAVEUNDERS - tells thw WM not to request save unders for pop-up
   *                 menus. A quick test using monochrome X11 shows that save
   *                 unders cost about 4Kbytes RAM, but saves a lot of
   *                 window re-draws if you have windows that take a while
   *                 to refresh. For xcolor, I assume the cost is more like
!  *                 4Kbytesx8 = 32kbytes (256 color).*/
  
  /*EF1 = -DNO_PAGER -DNON_VIRTUAL  -DNO_ICONS -DNO_SAVEUNDERS/**/
  
***************
*** 104,113 ****
  
  
  SRCS = fvwm.c configure.c events.c borders.c menus.c functions.c resize.c\
!        add_window.c pager.c move.c icons.c windows.c
   
  OBJS = fvwm.o configure.o events.o borders.o menus.o functions.o resize.o\
!        add_window.o pager.o move.o icons.o windows.o
  
  ComplexProgramTarget(fvwm)
  InstallNonExecFile(system.fvwmrc,$(FVWMDIR))
--- 104,113 ----
  
  
  SRCS = fvwm.c configure.c events.c borders.c menus.c functions.c resize.c\
!        add_window.c pager.c move.c icons.c windows.c dirmenu.c
   
  OBJS = fvwm.o configure.o events.o borders.o menus.o functions.o resize.o\
!        add_window.o pager.o move.o icons.o windows.o dirmenu.o
  
  ComplexProgramTarget(fvwm)
  InstallNonExecFile(system.fvwmrc,$(FVWMDIR))
diff -c --ignore-blank-lines --ignore-space-change --new-file --recursive fvwm.orig/Makefile.noImake fvwm/Makefile.noImake
*** fvwm.orig/Makefile.noImake	Wed Nov 10 21:01:20 1993
--- fvwm/Makefile.noImake	Tue Nov 16 11:51:13 1993
***************
*** 100,108 ****
  CFLAGS = $(COPTS) -I$(INCROOT) $(FFLAGS)
  
  SRCS = fvwm.c configure.c events.c borders.c menus.c functions.c resize.c \
!         add_window.c pager.c move.c icons.c windows.c
  OBJS = fvwm.o configure.o events.o borders.o menus.o functions.o resize.o \
! 	add_window.o pager.o move.o icons.o windows.o
  
  fvwm: $(OBJS)
  	$(CC) $(CFLAGS) -o fvwm $(OBJS) $(LIBS) 
--- 100,108 ----
  CFLAGS = $(COPTS) -I$(INCROOT) $(FFLAGS)
  
  SRCS = fvwm.c configure.c events.c borders.c menus.c functions.c resize.c \
!         add_window.c pager.c move.c icons.c windows.c dirmenu.c
  OBJS = fvwm.o configure.o events.o borders.o menus.o functions.o resize.o \
! 	add_window.o pager.o move.o icons.o windows.o dirmenu.o
  
  fvwm: $(OBJS)
  	$(CC) $(CFLAGS) -o fvwm $(OBJS) $(LIBS) 
diff -c --ignore-blank-lines --ignore-space-change --new-file --recursive fvwm.orig/configure.c fvwm/configure.c
*** fvwm.orig/configure.c	Wed Nov 10 13:02:43 1993
--- fvwm/configure.c	Fri Nov 12 12:59:20 1993
***************
*** 173,178 ****
--- 173,179 ----
    {"Stick",        set_func,(char **)F_STICK},
    {"CirculateUp",  set_func,(char **)F_CIRCULATE_UP},
    {"CirculateDown",set_func,(char **)F_CIRCULATE_DOWN},
+   {"ExecDir",	   set_func,(char **)F_EXEC_DIR},
  #ifndef NON_VIRTUAL
    {"Scroll",       set_func,(char **)F_SCROLL},
    {"GotoPage",     set_func,(char **)F_GOTO_PAGE},
diff -c --ignore-blank-lines --ignore-space-change --new-file --recursive fvwm.orig/dirmenu.c fvwm/dirmenu.c
*** fvwm.orig/dirmenu.c	Thu Jan  1 00:00:00 1970
--- fvwm/dirmenu.c	Tue Nov 16 11:40:08 1993
***************
*** 0 ****
--- 1,99 ----
+ /* The following by RGtti */
+ 
+ #include <stdio.h>
+ #include <string.h>
+ #include <ctype.h>
+ #include <dirent.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
+ #include "fvwm.h"
+ #include "menus.h"
+ #include "misc.h"
+ #include "parse.h"
+ #include "screen.h"
+ 
+ MenuRoot* NewMwnuRoot(char*);
+ void AddToMenu(MenuRoot*,char*,char*,char*,int,int,int);
+ void MakeMenu(MenuRoot*);
+ 
+ #define MAX_DIRMENU_ENTRY 255
+ char* commands[MAX_DIRMENU_ENTRY];
+ char* cnames[MAX_DIRMENU_ENTRY];
+ char* names[MAX_DIRMENU_ENTRY];
+ int used_names;
+ 
+ MenuRoot* create_dir_menu(char* dirname) {
+ 
+   MenuRoot* m;
+   DIR *dp;
+   struct dirent *entry;
+   struct stat status;
+   int dirnlen,namelen;
+   char *cname, *command, *name;
+ 
+   m=NewMenuRoot(dirname);
+   AddToMenu(m,dirname,NULL,NULL,F_TITLE,0,0); 
+   used_names=0;
+   dirnlen=strlen(dirname);
+ 
+   dp=opendir(dirname);
+ 
+   if(dp!=NULL) {
+     for(entry=readdir(dp);((entry!=NULL)&&(used_names<MAX_DIRMENU_ENTRY));
+ 	entry=readdir(dp)) {
+       namelen=strlen(entry->d_name);
+       name=(names[used_names]=(char *)safemalloc(namelen+1));
+       cname=(cnames[used_names]=(char *)safemalloc(namelen+dirnlen+1));
+       command=(commands[used_names]=(char *)safemalloc(namelen+dirnlen+10));
+       strcpy(name,entry->d_name);
+       strcpy(cname,dirname);
+       strcat(cname,name);
+       sprintf(command,"exec %s &\000",cname);
+       stat(cname,&status);
+       if((!access(cname,X_OK))&&(!S_ISDIR(status.st_mode)))  
+ 	AddToMenu(m,name,NULL,command,F_EXEC,0,0);
+       used_names++;
+     }
+   }
+ 
+   MakeMenu(m);
+   return m;
+ }
+ 
+ void delete_dir_menu(MenuRoot* m) {
+ 
+   MenuItem *current, *tmp;
+   int i;
+ 
+   if ( m==NULL ) return;
+ 
+   current = m->first;
+ 
+   while( current != NULL ) {
+     tmp=current;
+     current = current->next;
+     free(tmp);
+   }
+ 
+   XDestroyWindow(dpy,m->w);
+   free(m);
+ 
+   for(i=0;i<used_names;i++) {
+     free(names[i]);
+     free(cnames[i]);
+     free(commands[i]);
+   }
+ }
+ 
+ int do_menu_exec_dir(char* action) {
+ 
+   int tmp;
+   MenuRoot* dirmenu;
+ 
+   dirmenu = create_dir_menu(action);
+   tmp=do_menu(dirmenu);
+   delete_dir_menu(dirmenu);
+ 
+   return tmp;
+ 
+ }
diff -c --ignore-blank-lines --ignore-space-change --new-file --recursive fvwm.orig/functions.c fvwm/functions.c
*** fvwm.orig/functions.c	Wed Nov 10 16:49:16 1993
--- fvwm/functions.c	Tue Nov 16 11:53:19 1993
***************
*** 50,55 ****
--- 50,58 ----
  
  extern FvwmWindow *Tmp_win;
  
+ MenuRoot* create_dir_menu(char*);
+ void delete_dir_menu(MenuRoot*);
+ int do_menu_exec_dir(char*);
  
  void FocusOn(FvwmWindow *t);
  extern char **g_argv;
***************
*** 459,464 ****
--- 463,475 ----
        do_menu(menu);
        break;
  
+     case F_EXEC_DIR:
+       ActiveItem = NULL;
+       ActiveMenu = NULL;
+       menuFromFrameOrWindowOrTitlebar = FALSE;
+       do_menu_exec_dir(action);
+       break;
+ 
       case F_MAXIMIZE:
        if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease))
  	break;
diff -c --ignore-blank-lines --ignore-space-change --new-file --recursive fvwm.orig/fvwm.1 fvwm/fvwm.1
*** fvwm.orig/fvwm.1	Wed Nov 10 19:45:36 1993
--- fvwm/fvwm.1	Fri Nov 12 17:01:20 1993
***************
*** 802,807 ****
--- 802,811 ----
  .sp
  .fi
  
+ .IP "ExecDir \fIname directory\fP"
+ Display a pop up menu with all the executable (from the user) files in the 
+ specified directory. Note that \fIdirectory\fP is read every time the pop-up 
+ is displayed. The directory name \fIMUST\fP terminate with a slash.
  .IP "Popup \fI\"PopupName\"\fP"
  NOTE: This built-in takes a slightly different form when used to bind
  a sub-menu into a menu than it does when binding the main menu to a key
diff -c --ignore-blank-lines --ignore-space-change --new-file --recursive fvwm.orig/menus.c fvwm/menus.c
*** fvwm.orig/menus.c	Wed Nov 10 04:20:11 1993
--- fvwm/menus.c	Fri Nov 12 13:31:52 1993
***************
*** 70,75 ****
--- 70,76 ----
  void DrawUnderline(Window w, GC gc, int x, int y, char *txt, int off);
  #endif /* MENU_HOTKEYS */
  int UpdateMenu(void); 
+ int do_menu_exec_dir(char*);
  
  /****************************************************************************
   *
***************
*** 227,233 ****
  #endif /* MENU_HOTKEYS */
  
    d=(Scr.EntryHeight-7)/2;
!   if(mi->func == F_POPUP)
      DrawTrianglePattern(mr->w, ShadowGC, ReliefGC, ShadowGC,
  		  mr->width-d-8, y_offset+d-1, mr->width-d-1, y_offset+d+7);
    if((mi->item_num  == 0)&&(menu_on>1))
--- 228,234 ----
  #endif /* MENU_HOTKEYS */
  
    d=(Scr.EntryHeight-7)/2;
!   if((mi->func == F_POPUP)||(mi->func == F_EXEC_DIR))
      DrawTrianglePattern(mr->w, ShadowGC, ReliefGC, ShadowGC,
  		  mr->width-d-8, y_offset+d-1, mr->width-d-1, y_offset+d+7);
    if((mi->item_num  == 0)&&(menu_on>1))
***************
*** 346,354 ****
      return retval;
  
    /* creatpe a new sub-menu */
!   if((ActiveItem->func == F_POPUP)&&(x>(3*ActiveMenu->width>>2)))
      {
!       retval = do_menu(ActiveItem->menu);
        /* Unfortunately, this is needed (why?) for multi-screen operation */
        flush_expose(ActiveMenu->w);
        for (mi = ActiveMenu->first; mi != NULL; mi = mi->next)
--- 347,357 ----
      return retval;
  
    /* creatpe a new sub-menu */
!   if(((ActiveItem->func == F_POPUP)||(ActiveItem->func == F_EXEC_DIR))
!      &&(x>(3*ActiveMenu->width>>2)))
      {
!       retval = (ActiveItem->func != F_EXEC_DIR) ? do_menu(ActiveItem->menu)
! 	: do_menu_exec_dir(ActiveItem->action);
        /* Unfortunately, this is needed (why?) for multi-screen operation */
        flush_expose(ActiveMenu->w);
        for (mi = ActiveMenu->first; mi != NULL; mi = mi->next)
diff -c --ignore-blank-lines --ignore-space-change --new-file --recursive fvwm.orig/parse.h fvwm/parse.h
*** fvwm.orig/parse.h	Tue Oct 19 20:31:30 1993
--- fvwm/parse.h	Fri Nov 12 11:37:46 1993
***************
*** 65,69 ****
--- 65,70 ----
  #define F_FUNCTION              25
  #define F_EXEC			100	/* string */
  #define F_POPUP			101	/* string */
+ #define F_EXEC_DIR		200	/* RGtti */
  
  #endif /* _PARSE_ */

