On Fri, Jan 16, 2004 at 05:21:22PM +0100, Uwe Pross wrote:
> Hi there,
> 
> On 16 Jan 2004 at 14:58:58 +0100, Olivier Chapuis wrote:
> 
> > Use
> > 
> >     fprintf(stderr,"*** FVWM Bell: Abort function %s\n", action);
> 
> I got:
> 
> *** FVWM Bell: functions.c line 987 [MarkWindowAsActiveFunc] ***
> 
> which comes from FvwmEvent. So I guess it is my fault :-\
>

I do not think that it is your fault :o)

If you use my version of FVWM you never get these beeps (and the
function will be executed). But, for some reasons dominik does not
want that your setup work. The last thread on this subject start here:

ven 07 nov   Olivier Chapuis Re: FVWM: gkrellm and FVWM v2.5.8

on the fvwm workers list (there was an other thread on this subject
during the summer). I attach a patch (small) against the current cvs
which always execute totally immediate function.

I do not understand what you want to do with your FvwmEvent, but you
can apply the patch and see if it causes problem (when you use your
transient FvwmWinList or FrameMaker).

Regards, Olivier
Index: fvwm/functions.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/functions.c,v
retrieving revision 1.260
diff -u -r1.260 functions.c
--- fvwm/functions.c    5 Jul 2003 01:37:47 -0000       1.260
+++ fvwm/functions.c    16 Jan 2004 23:24:24 -0000
@@ -79,6 +79,7 @@
        FunctionItem *last_item;         /* last item in function */
        char *name;                      /* function name */
        unsigned int use_depth;
+       Bool already_grab_warn;
 } FvwmFunction;
 
 /* Types of events for the FUNCTION builtin */
@@ -120,7 +121,7 @@
 }
 
 /*
- * Defer the execution of a function to the next button press if the context is
+ * Defer the execution of a function to the next button press if the context
  * C_ROOT
  *
  *  Inputs:
@@ -153,6 +154,11 @@
        if (wcontext != C_ROOT && wcontext != C_NO_CONTEXT && fw != NULL &&
            wcontext != C_EWMH_DESKTOP)
        {
+               if (Scr.flags.is_executing_complex_function &&
+                   trigger_evtype == ButtonPress)
+               {
+                       trigger_evtype = ButtonRelease;
+               }
                if (FinishEvent == ButtonPress ||
                    (FinishEvent == ButtonRelease &&
                     trigger_evtype != ButtonPress))
@@ -875,6 +881,8 @@
        exec_context_change_mask_t mask;
        int trigger_evtype;
        XEvent *te;
+       Bool need_ungrab = False;
+       Bool grab_fast = True;
 
        if (cond_rc == NULL)
        {
@@ -960,6 +968,17 @@
                        {
                                do_allow_unmanaged_immediate &= fi->flags;
                                ImmediateNeedsTarget = True;
+                               if (!grab_fast)
+                               {
+                                       break;
+                               }
+                       }
+               }
+               if (fi->condition != CF_IMMEDIATE)
+               {
+                       grab_fast = False;
+                       if (ImmediateNeedsTarget)
+                       {
                                break;
                        }
                }
@@ -986,12 +1005,46 @@
        /* we have to grab buttons before executing immediate actions because
         * these actions can move the window away from the pointer so that a
         * button release would go to the application below. */
-       if (!GrabEm(CRS_NONE, GRAB_NORMAL))
+       if (grab_fast)
        {
-               func->use_depth--;
-               XBell(dpy, 0);
-               __cf_cleanup(&depth, arguments, cond_rc);
-               return;
+               if (!GrabEmWithAttempts(CRS_NONE, GRAB_NORMAL, 1))
+               {
+                       /* execute the function anyway */
+                       if (1 || !func->already_grab_warn)
+                       {
+                               func->already_grab_warn = True;
+                               fvwm_msg(
+                                       WARN, "ComplexFunction",
+                                       "Cannot grab the cursor when "
+                                       "executing %s", action);
+                       }
+               }
+               else
+               {
+                       need_ungrab = True;
+               }
+       }
+       else
+       {
+               if (!GrabEm(CRS_NONE, GRAB_NORMAL))
+               {
+                       if (1 || !func->already_grab_warn)
+                       {
+                               func->already_grab_warn = True;
+                               fvwm_msg(
+                                       WARN, "ComplexFunction",
+                                       "Cannot grab the cursor, abort "
+                                       "%s execution", action);
+                       }
+                       func->use_depth--;
+                       XBell(dpy, 0);
+                       __cf_cleanup(&depth, arguments, cond_rc);
+                       return;
+               }
+               else
+               {
+                       need_ungrab = True;
+               }
        }
        exc2 = exc_clone_context(exc, &ecc, mask);
        __run_complex_function_items(
@@ -1025,7 +1078,10 @@
        {
                func->use_depth--;
                __cf_cleanup(&depth, arguments, cond_rc);
-               UngrabEm(GRAB_NORMAL);
+               if (need_ungrab)
+               {
+                       UngrabEm(GRAB_NORMAL);
+               }
                return;
        }
 
@@ -1039,7 +1095,10 @@
                {
                        func->use_depth--;
                        __cf_cleanup(&depth, arguments, cond_rc);
-                       UngrabEm(GRAB_NORMAL);
+                       if (need_ungrab)
+                       {
+                               UngrabEm(GRAB_NORMAL);
+                       }
                        return;
                }
        }
@@ -1110,7 +1169,10 @@
         * function will receive MotionNotify events with a button held down!
         * The results are unpredictable.  E.g. rxvt interprets the
         * ButtonMotion as user input to select text. */
-       UngrabEm(GRAB_NORMAL);
+       if (need_ungrab)
+       {
+               UngrabEm(GRAB_NORMAL);
+       }
 #endif
        fev_set_evpos(&d, x, y);
        fev_fake_event(&d);
@@ -1125,8 +1187,10 @@
         */
        func->use_depth--;
        __cf_cleanup(&depth, arguments, cond_rc);
-       UngrabEm(GRAB_NORMAL);
-
+       if (need_ungrab)
+       {
+               UngrabEm(GRAB_NORMAL);
+       }
        return;
 }
 
@@ -1143,6 +1207,7 @@
        tmp->last_item = NULL;
        tmp->name = stripcpy(name);
        tmp->use_depth = 0;
+       tmp->already_grab_warn = False;
        Scr.functions = tmp;
 
        return tmp;
@@ -1277,7 +1342,7 @@
        return;
 }
 
-void find_func_t(char *action, short *func_t, unsigned char *flags)
+void find_func_t(char *action, short *func_t, FUNC_FLAGS_TYPE *flags)
 {
        int j, len = 0;
        char *endtok = action;
Index: fvwm/misc.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/misc.c,v
retrieving revision 1.145
diff -u -r1.145 misc.c
--- fvwm/misc.c 25 Aug 2003 06:47:08 -0000      1.145
+++ fvwm/misc.c 16 Jan 2004 23:24:25 -0000
@@ -80,17 +80,6 @@
        return;
 }
 
-/* ---------------------------- interface functions ------------------------ */
-
-int GetTwoArguments(
-       char *action, int *val1, int *val2, int *val1_unit, int *val2_unit)
-{
-       *val1_unit = Scr.MyDisplayWidth;
-       *val2_unit = Scr.MyDisplayHeight;
-
-       return GetTwoPercentArguments(action, val1, val2, val1_unit, val2_unit);
-}
-
 /*
  * Grab the pointer.
  * grab_context: GRAB_NORMAL, GRAB_BUSY, GRAB_MENU, GRAB_BUSYMENU,
@@ -102,7 +91,7 @@
  */
 #define DEBUG_GRAB 0
 #if DEBUG_GRAB
-void print_grab_stats(char *text)
+static void print_grab_stats(char *text)
 {
        int i;
 
@@ -117,7 +106,7 @@
 }
 #endif
 
-Bool GrabEm(int cursor, int grab_context)
+Bool __GrabEm(int cursor, int grab_context, int attempt)
 {
        int i = 0;
        int val = 0;
@@ -180,18 +169,18 @@
                        grab_win = Scr.Root;
                }
                /* retry to grab the busy cursor only once */
-               rep = 2;
+               rep = (attempt)? attempt:2;
                break;
        case GRAB_PASSIVE:
                /* cannot happen */
                return False;
        case GRAB_FREEZE_CURSOR:
                grab_win = (PressedW != None) ? PressedW : Scr.NoFocusWin;
-               rep = 2;
+               rep = (attempt)? attempt:2;
                break;
        default:
                grab_win = Scr.Root;
-               rep = NUMBER_OF_GRAB_ATTEMPTS;
+               rep = (attempt)? attempt:NUMBER_OF_GRAB_ATTEMPTS;
                break;
        }
 
@@ -218,11 +207,12 @@
                default:
                        /* If you go too fast, other windows may not get a
                         * chance to release any grab that they have. */
-                       i++;
                        if (grab_context == GRAB_FREEZE_CURSOR)
                        {
+                               i++;
                                break;
                        }
+                       i++;
                        if (i < rep)
                        {
                                usleep(1000 * TIME_BETWEEN_GRAB_ATTEMPTS);
@@ -246,6 +236,28 @@
        return True;
 }
 
+/* ---------------------------- interface functions ------------------------ */
+
+int GetTwoArguments(
+       char *action, int *val1, int *val2, int *val1_unit, int *val2_unit)
+{
+       *val1_unit = Scr.MyDisplayWidth;
+       *val2_unit = Scr.MyDisplayHeight;
+
+       return GetTwoPercentArguments(action, val1, val2, val1_unit, val2_unit);
+}
+
+Bool GrabEm(int cursor, int grab_context)
+{
+
+       return __GrabEm(cursor, grab_context, 0);
+
+}
+
+Bool GrabEmWithAttempts(int cursor, int grab_context, int attempts)
+{
+       return __GrabEm(cursor, grab_context, attempts);
+}
 
 /*
  *
Index: fvwm/misc.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/misc.h,v
retrieving revision 1.129
diff -u -r1.129 misc.h
--- fvwm/misc.h 29 Jun 2003 19:53:23 -0000      1.129
+++ fvwm/misc.h 16 Jan 2004 23:24:25 -0000
@@ -61,6 +61,8 @@
 
 Bool GrabEm(
        int cursor, int grab_context);
+Bool GrabEmWithAttempts(
+       int cursor, int grab_context, int attempts);
 Bool UngrabEm(
        int ungrab_context);
 int GetTwoArguments(

Reply via email to