Troubles in Commodity-land

A forum for general AmigaOS 4.x support questions that are not platform-specific
xenic
Posts: 1165
Joined: Sun Jun 19, 2011 12:06 am

Re: Troubles in Commodity-land

Post by xenic »

OldFart wrote:Don't worry: I am not easily offended. Really not.
That's good because it looks like my observations were incorrect :-)
AmigaOne X1000 with 2GB memory - OS4.1 FE

User avatar
OldFart
Posts: 55
Joined: Tue Jul 12, 2011 2:56 pm
Location: Groningen, Netherlands

Re: Troubles in Commodity-land

Post by OldFart »

@xenic
That's good because it looks like my observations were incorrect
We both learned a bit today, that's the upside.

However, I'm still looking for a way to intercept mouseclicks. A filterpattern of "rawmouse mouse_leftpress" does not cut any cake, although it is accepted as a 'proper' pattern. It looks like there is still something missing, or? I keep on looking.

OldFart
Sleeping X5000, eagerly awaiting awakening
Dead MicroA1
A1200 in ElBox, c/w Blizzard '040 @ 50MHz + SCSI module, ZIV-board c/w (o.a.) cv64/3d + flickerdoubler + FastATA-ZIV + Lots of SCSI gear (for sale, willing to split)
RaspBerry Pi 2B, 3B & 4B (4Gb)

xenic
Posts: 1165
Joined: Sun Jun 19, 2011 12:06 am

Re: Troubles in Commodity-land

Post by xenic »

OldFart wrote:
However, I'm still looking for a way to intercept mouseclicks. A filterpattern of "rawmouse mouse_leftpress" does not cut any cake, although it is accepted as a 'proper' pattern. It looks like there is still something missing, or? I keep on looking.
Perhaps it's for the best. If Commodities library intercepted and ate mouse clicks, the system would become almost useless. Apparently mouse buttons only work as qualifiers. I tried hotkey HOTKEY "lbutton a" and it works. On the other hand it will use hotkey HOTKEY "ctrl c" which works as a hotkey but prevents copying text.
AmigaOne X1000 with 2GB memory - OS4.1 FE

User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 591
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Troubles in Commodity-land

Post by broadblues »

xenic wrote:
OldFart wrote:
However, I'm still looking for a way to intercept mouseclicks. A filterpattern of "rawmouse mouse_leftpress" does not cut any cake, although it is accepted as a 'proper' pattern. It looks like there is still something missing, or? I keep on looking.
Perhaps it's for the best. If Commodities library intercepted and ate mouse clicks, the system would become almost useless.
Hmmm, I'm sure you really thought that statement through :-) ClickToFront? DepthToFront? BorderResize?
Apparently mouse buttons only work as qualifiers.
In the context of a hotkey I think that's probably true.
I tried hotkey HOTKEY "lbutton a" and it works. On the other hand it will use hotkey HOTKEY "ctrl c" which works as a hotkey but prevents copying text.
CTRL-C for copying text? You may be in the wrong OS :-)

It would stop you from sending a ctrl_C to shell program though.

Lots of choices not all good.

User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 591
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Troubles in Commodity-land

Post by broadblues »

OldFart wrote:
However, I'm still looking for a way to intercept mouseclicks. A filterpattern of "rawmouse mouse_leftpress" does not cut any cake, although it is accepted as a 'proper' pattern. It looks like there is still something missing, or? I keep on looking.

OldFart
What exactly are you trying to do? If you want to act of a mouse key up or down event, a simple filter might not be the way to go.

xenic
Posts: 1165
Joined: Sun Jun 19, 2011 12:06 am

Re: Troubles in Commodity-land

Post by xenic »

broadblues wrote: Hmmm, I'm sure you really thought that statement through :-) ClickToFront? DepthToFront? BorderResize?
I said "intercepted and ate mouse clicks" which other commodities aren't doing or you wouldn't be able click on gadgets in the normal way. What I mean by "ate" is that a commodity is using a translate CxObject which prevents events from being passed to other commodities or applications.
In the context of a hotkey I think that's probably true.
I think the context of this topic is hotkeys, but yes, in the context of hotkeys.
CTRL-C for copying text? You may be in the wrong OS :-)
It would stop you from sending a ctrl_C to shell program though.
Lots of choices not all good.
I was thinking RAMIGA-C and wrote CTRL-C, both of which would be bad choices.
AmigaOne X1000 with 2GB memory - OS4.1 FE

xenic
Posts: 1165
Joined: Sun Jun 19, 2011 12:06 am

Re: Troubles in Commodity-land

Post by xenic »

OldFart wrote: I keep on looking.
Try looking in one of the OS3 developer CD's for an example called "leftymouse". I haven't had a chance to examine it closely but it looks like it sets up a catch-all filter and then checks the CxMsg input event structure for mouse events.

EDIT: I tested one of the "leftymouse" binary from a developer CD and it appears to intercept left and right mouse button events and reverse them for left handed mouse users. It's quite confusing for someone accustomed to the normal mouse buttons. The left button becomes the menu button and the right button becomes the click-on button. One of the binaries on the v 2.1 CD appears to be corrupted and crashes but the one in the RKM examples worked for me.
AmigaOne X1000 with 2GB memory - OS4.1 FE

User avatar
OldFart
Posts: 55
Joined: Tue Jul 12, 2011 2:56 pm
Location: Groningen, Netherlands

Re: Troubles in Commodity-land

Post by OldFart »

@All

Well, a new year, a new opportunity: happy newyear to all of you!

After a lot of testing I found this to be working:
"rawkey lshift a", which is working. For lshift one can just take anyone of lshift, rshift, shift, capslock, caps, etc., etc and for 'a' one can take any other key OR one of the special keys like 'home' or 'esc' or 'f1' or whatever there is.

Both "diskremoved" and "diskinserted" without any further qualification notifies of a USB-stick being removed resp. inserted, so it is safe to say that they work as may be expected.

However, "rawmouse mouse_rightpress", although accepted, does not give any notifications of clicking the L/H mouse button, neither do qualifications of "mouse_middlepress" or "mouse_leftpress". Even "rawmouse relativemouse mouse_rightpress" is accepted, but provides NO notifications.

"rawmouse relativemouse pointerpos" gives an error and so is not accepted.

"pointerpos" without any further qualification is accepted, but NO notifications.

My question still remains: Am I doing something wrong? Or am I overlooking c.q. misinterpreting something? Or...

For testing I've built this program (make lines at bottom):

Code: Select all

/*
** main.c - Simple Keyword tester commodity
*/

#include <exec/libraries.h>
#include <libraries/commodities.h>
#include <dos/dos.h>
 
#include <proto/exec.h>
#include <proto/commodities.h>
#include <proto/dos.h>

#define ELSE_ERROR(Text) else {IDOS->Printf("ERROR: Failed to %s\n", Text);}
#define EVT_HOTKEY 1L

#define TEMPLATE "PATTERN/A"

enum ArgID {AID_PATTERN
           ,AID_LAST
           };
 
struct NewBroker newbroker = {  NB_VERSION
                             , "Amiga Keyworder"
                             , "A Simple Keyword tester"
                             , "A simple Keyword tester commodity"
                             ,  NBU_UNIQUE | NBU_NOTIFY
                             , 0
                             , 0
                             , NULL
                             , 0
                             };

 
int main(int argc, char *argv[])
{
  IDOS->Printf("INFO : Setup commodity...\n");

  STRPTR Args;
  struct RDArgs *rda = IDOS->ReadArgs(TEMPLATE, (APTR)&Args, NULL);

  if (rda != NULL)
   {
    newbroker.nb_Port = IExec->AllocSysObject(ASOT_PORT, TAG_END);

    if (newbroker.nb_Port != NULL)
     {
      CxObj *broker = ICommodities->CxBroker(&newbroker, NULL);

      uint32 cxsigflag = 1L << newbroker.nb_Port->mp_SigBit;
 
      if (broker != NULL)
       {
        CxObj *filter  = CxFilter(Args),
              *sender,
              *translate;
        int32 CxErr;

        if (filter != NULL)
         {
          ICommodities->AttachCxObj(broker, filter);
 
          if (sender = CxSender(newbroker.nb_Port, EVT_HOTKEY))
           {
            ICommodities->AttachCxObj(filter, sender);
 
            if (translate = CxTranslate(NULL))
             {
              ICommodities->AttachCxObj(filter, translate);
 
              CxErr = ICommodities->CxObjError(filter);

              if (CxErr == 0)
               {
                CxMsg *msg;
                uint32 msgid,
                       msgtype,
                       sigrcvd;

                ICommodities->ActivateCxObj(broker, 1L);
                BOOL Done = FALSE;
                IDOS->Printf("INFO : Here we go...\n");

                while (Done == FALSE)
                 {
                  sigrcvd = IExec->Wait(SIGBREAKF_CTRL_C | cxsigflag);
  
                  while (msg = (CxMsg *)IExec->GetMsg(newbroker.nb_Port))
                   {
                    msgid   = ICommodities->CxMsgID(msg);
                    msgtype = ICommodities->CxMsgType(msg);
                    IExec->ReplyMsg((struct Message *)msg);
 
                    switch (msgtype)
                     {
                      case CXM_IEVENT:
                       {
                        IDOS->Printf("An event, ");
 
                        switch(msgid)
                         {
                          case EVT_HOTKEY:
                           {
                            IDOS->Printf("you are notified due to [ %s ]\n", Args);

                            break;
                           }

                          default:
                           {
                            IDOS->Printf("which is unknown.\n");
                           }
                         }
 
                        break;
                       }

                      case CXM_COMMAND:
                       {
                        IDOS->Printf("A command: ");

                        switch(msgid)
                         {
                          case CXCMD_DISABLE:
                           {
                            IDOS->Printf("CXCMD_DISABLE\n");
                            ICommodities->ActivateCxObj(broker, 0L);

                            break;
                           }
 
                          case CXCMD_ENABLE:
                           {
                            IDOS->Printf("CXCMD_ENABLE\n");
                            ICommodities->ActivateCxObj(broker, 1L);

                            break; 
                           }

                          case CXCMD_KILL:
                           {
                            IDOS->Printf("CXCMD_KILL\n");
                            Done = TRUE;

                            break;
                           }

                          case CXCMD_UNIQUE:
                           {
                            IDOS->Printf("CXCMD_UNIQUE\n");
                            Done = TRUE;

                            break;
                           }

                          default:
                           {
                            IDOS->Printf("Unknown msgid\n");
                           }
                         }

                        break;
                       }

                      default:
                       {
                        IDOS->Printf("Unknown msgtype\n");
                       }
                     }
  
                    if (sigrcvd & SIGBREAKF_CTRL_C)
                     {
                      Done = TRUE;
                      IDOS->Printf("CTRL C signal break\n");
                     }
                   }
                 }

                while (msg = (CxMsg *)IExec->GetMsg(newbroker.nb_Port))
                 {
                  IExec->ReplyMsg((struct Message *)msg);
                 }

                IDOS->Printf("INFO : ...and here we stopped\n");
               }
              else
               {
                IDOS->Printf("ERROR: %ld\n", CxErr);
               }
             }
             ELSE_ERROR("Create translator");

           }
          ELSE_ERROR("Create sender");

         }
        ELSE_ERROR("Create filter");

        ICommodities->DeleteCxObjAll(broker);
       }
      ELSE_ERROR("Create broker");

      IExec->FreeSysObject(ASOT_PORT, newbroker.nb_Port);
     }
    ELSE_ERROR("Create MsgPort");

    IDOS->FreeArgs(rda);
   }
  ELSE_ERROR("Read Arguments");
 
  return 0;
}


/*
SWITCHES = -W                     \
           -Werror                \
           -Wmissing-prototypes   \
           -Wsign-compare         \
           -Wundef                \
           -Wshadow               \
           -Wwrite-strings        \

KTC : main.c
	gcc main.c -lauto -o KTC $(SWITCHES)
*/
Compile, start it from the shell and provide the required filterspec as an argument. When started a second time, in a second shell, the first one will stop.

OldFart
Sleeping X5000, eagerly awaiting awakening
Dead MicroA1
A1200 in ElBox, c/w Blizzard '040 @ 50MHz + SCSI module, ZIV-board c/w (o.a.) cv64/3d + flickerdoubler + FastATA-ZIV + Lots of SCSI gear (for sale, willing to split)
RaspBerry Pi 2B, 3B & 4B (4Gb)

xenic
Posts: 1165
Joined: Sun Jun 19, 2011 12:06 am

Re: Troubles in Commodity-land

Post by xenic »

@OldFart
I assume you've posted the above code for others to test but there are several problems. When I copy your program from the above post, it appears the tabs are replaced with hexadecimal "A020" and the code won't compile when pasted into a text editor and saved to a file. I suggest you replace tabs with spaces in your text editor before posting code in these forums unless someone can tell me how to copy program text without introducing binary values that won't compile.

After copying your program, stripping the hex "A020" with a hex editor, saving the text and compiling it I discovered that I was unable to quit the program with "Control C" and had to open Exchange to shut it down.

After a lot of discussion on this topic it appears that you're not going to get an answer unless someone with access to the commodities.library code can determine what qualifiers and codes are acceptable and create a list of them in the autodocs or WIKI.
AmigaOne X1000 with 2GB memory - OS4.1 FE

User avatar
OldFart
Posts: 55
Joined: Tue Jul 12, 2011 2:56 pm
Location: Groningen, Netherlands

Re: Troubles in Commodity-land

Post by OldFart »

@xenic
I suggest you replace tabs with spaces in your text editor before posting
Uh, me??? Using tabs in code??? No, not me, definitly not. (Yikes!)
As Linus Thorvalds remarkes in his Linux coding guidelines, is that not all tabsettings are globally equal ("like defining Pi to be anything but 3.14"). A hardspace is unubiquitous in that respect, so...

I created the code on an Amiga (NotePad), moved it over to a WIndows laptop, which can't cope well with the Amiga's end-of-line. I then mangled it through a browser, which does a nice job of interpreting, and finally copied it from there into this forum.

I'll see what I can do about this.

OldFart

EDIT:
Well, I did copy the text from the posting into Window's NotePad, saved it to a USB-thingy, took it to the Amiga, copied it back into where it first came from and compiled it. Not one single problem...
Sleeping X5000, eagerly awaiting awakening
Dead MicroA1
A1200 in ElBox, c/w Blizzard '040 @ 50MHz + SCSI module, ZIV-board c/w (o.a.) cv64/3d + flickerdoubler + FastATA-ZIV + Lots of SCSI gear (for sale, willing to split)
RaspBerry Pi 2B, 3B & 4B (4Gb)

Post Reply