Subject:
Re: [nanogui] RE: Newbie question--passing events between programs
From:
Jordan Crouse ####@####.####
Date:
29 Jan 2002 15:45:15 -0000
Message-Id: <E16VaOH-00013U-00@ns.censoft.com>
Its very easy - you have two options. Either you can use the build in IPC
(which has the advantage of already existing on your system), or you can grow
your own IPC with a Unix socket. It works just like a network socket, and it
has the advantage of being a file descriptor, so you can register it with
GrRegisterInput() and have Microwindows poll it for you.
Jordan
On Tuesday 29 January 2002 05:23, Henry Chea mentioned:
> Hi again,
>
> Yeah I know I'm replying to my own message, but I'm desperate *desperate*!
> =)
>
> I have been searching for countless hours how to solve my problem (making a
> control program pass events via the Nano-X server to another program that
> listens for the events), and have come across what is perhaps the solution
> though I do not know how to use it:
>
> GrRegisterInput(int fd)
> GrPrepareSelect (int * maxfd , void * rfdset)
> and
> GrServiceSelect (void * rfdset , GR_FNCALLBACKEVENT fncb)
>
> Those three functions seem to be what I need, but I can't figure out how to
> use them nor can I find any documentation/examples on their use (I tried
> decifering the source code too but I'm not that smart).
>
> Can someone please help me? I would be very greatful!
>
> Maybe point me to examples, docs, or perhaps edit my source code below to
> show how to solve the problem?
>
> Thanks again,
> Henry Chea
> Semcon Sweden AB
>
> ****************************
> //control.c
> #include <stdio.h>
> #define MWINCLUDECOLORS
> #include "microwin/nano-X.h"
>
> GR_WINDOW_ID control_wid;
> GR_GC_ID gc;
>
> int control_fd;
>
> void event_handler (GR_EVENT *event);
>
> int main (void)
> {
> if ((control_fd = GrOpen()) < 0)
> {
> fprintf (stderr, "GrOpen failed");
> exit (1);
> }
>
>
> gc = GrNewGC();
> GrSetGCUseBackground (gc, GR_FALSE);
> GrSetGCForeground (gc, BLUE);
>
> control_wid = GrNewWindowEx (GR_WM_PROPS_NOMOVE |
> GR_WM_PROPS_BORDER |
> GR_WM_PROPS_NOAUTOMOVE |
> GR_WM_PROPS_NOAUTORESIZE,
> "Control Window",
> GR_ROOT_WINDOW_ID,
> 0, 0, 150, 478, YELLOW);
>
> GrSelectEvents (control_wid, GR_EVENT_MASK_EXPOSURE |
> GR_EVENT_MASK_BUTTON_DOWN);
>
> GrMapWindow (control_wid);
> GrMainLoop (event_handler);
> }
>
> void event_handler (GR_EVENT *event)
> {
> switch (event->type)
> {
> case GR_EVENT_TYPE_EXPOSURE:
> GrText (control_wid, gc, 20, 20,
> "Click me", -1, GR_TFASCII);
> break;
>
> case GR_EVENT_TYPE_BUTTON_DOWN:
> GrClearWindow (control_wid , GR_TRUE);
> ???SOMEHOW_SEND_EVENT_TO_NANO-X_HERE???
> break;
> }
> }
>
> ******************************
> //SLAVE.C
> #include <stdio.h>
> #define MWINCLUDECOLORS
> #include "microwin/nano-X.h"
>
> GR_WINDOW_ID slave_wid;
> GR_GC_ID gc;
>
> void event_handler (GR_EVENT *event);
>
> int slave_fd;
>
> int main (void)
> {
> if ((slave_fd = GrOpen()) < 0)
> {
> fprintf (stderr, "GrOpen failed");
> exit (1);
> }
>
> gc = GrNewGC();
> GrSetGCUseBackground (gc, GR_FALSE);
> GrSetGCForeground (gc, RED);
>
> slave_wid = GrNewWindowEx (GR_WM_PROPS_APPFRAME |
> GR_WM_PROPS_CAPTION |
> GR_WM_PROPS_CLOSEBOX,
> "slave Window",
> GR_ROOT_WINDOW_ID,
> 150, 150, 200, 100, WHITE);
>
> GrSelectEvents (slave_wid, GR_EVENT_MASK_CLOSE_REQ|
> ???EVENT_PASSED_FROM_CONTROL_PROGRAM???);
>
> GrMapWindow (slave_wid);
> GrMainLoop (event_handler);
> }
>
> void event_handler (GR_EVENT *event)
> {
> switch (event->type)
> {
> case GR_EVENT_TYPE_CLOSE_REQ:
> GrClose();
> exit (0);
>
> case ???EVENT_PASSED_FROM_CONTROL_PROGRAM???:
> GrText (slave_wid, gc, 50, 50,
> "Received a message from control", -1, GR_TFASCII);
> break;
> }
> }
> ******************************
>
> -----Original Message-----
> From: Henry Chea
> To: ####@####.####
> Sent: 1/28/2002 10:10 AM
> Subject: Newbie question--passing events between programs
>
> Hi all,
>
> In Nano-X I want to create a "control" program that creates and passes
> events to "slave" programs. That is to say that the slave programs
> listen for events created by the control program.
>
> Ideally I would like to make a control program that creates and inserts
> events into the Nano-X server event queue.
>
> Can anyone help show me how to do this?
>
> Thanks for the help,
>
> Henry Chea
> Semcon Sweden AB
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ####@####.####
> For additional commands, e-mail: ####@####.####