Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Multi head/multi window hello world

$
0
0
I am trying to write a large X app. I have successfully modified my xorg.conf to setup 4 monitors on an NVIDIA Quatro5200. I am trying to modify a simple hello world application to open a window on three of the four monitors. depending on the changes to loop the window creation section and event handler portion, i get either a Bus Error, Segmentation Fault, or a BadMatch. (Not sure where the BadMatch is coming from) Here is the code.


Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>

int main (int argc, char *argv[])
{
    Display                *display;
    Visual                  *visual[3];
    int                    depth[3];
    int                    text_x;
    int                    text_y;
    XSetWindowAttributes    frame_attributes[3];
    int                    screen_num;
    int                    screen_ind, i;
    unsigned int            display_width[3], display_height[3];
    Window                  frame_window[3];
    XFontStruct            *fontinfo = NULL;
    XGCValues              gr_values;
    GC                      graphical_context;
    XKeyEvent              event;
    char                    hello_string[] = "Hello X";
    int                    hello_string_length=strlen(hello_string);

    display = XOpenDisplay(NULL);

  for( i = 0; i < 3; i++ )
  {
    screen_num = i+1;
    visual[i] = DefaultVisual(display, screen_num);
    depth[i]  = DefaultDepth(display, screen_num);
    display_width[i]  = DisplayWidth(display, screen_num);
    display_height[i] = DisplayHeight(display, screen_num);

    frame_attributes[i].background_pixel = XBlackPixel(display, screen_num);
    frame_attributes[i].override_redirect = 1;

    /* create the application window */
    frame_window[i] = XCreateWindow(display, XRootWindow(display, screen_num),
                                0, 0, display_width[i], display_height[i], 0, depth[i],
                                InputOutput, visual[i], CWBackPixel|CWOverrideRedirect,
                                &frame_attributes[i]);
                                                                                                                 
    XSelectInput(display, frame_window[i], ExposureMask );

    if( fontinfo == NULL )
    {
      fontinfo = XLoadQueryFont(display, "10x20");

      if(fontinfo != NULL )
      {
        gr_values.font = fontinfo->fid;
        gr_values.foreground = XWhitePixel(display, screen_num);
        graphical_context = XCreateGC(display, frame_window[i],
                                      GCFont+GCForeground, &gr_values);
      }
    }

    XMapWindow(display, frame_window[i]);
  }

    while ( 1 ) {
fprintf(stdout, "1\n");
fflush(stdout);

        XNextEvent(display, (XEvent *)&event);

        switch ( event.type ) {
            case Expose:
            {
                XWindowAttributes window_attributes;
                int font_direction, font_ascent, font_descent;
                XCharStruct text_structure;

                if( event.window == frame_window[0] )
                {
                  hello_string[6] = '1';
                  screen_ind = 0;
                }
                else if( event.window == frame_window[1] )
                {
                  hello_string[6] = '2';
                  screen_ind = 1;
                }
                else if( event.window == frame_window[2] )
                {
                  hello_string[6] = '3';
                  screen_ind = 2;
                }
                else
                {
                  printf("event.window = %d\n", (int)event.window );
                  return(0);
                }
fprintf(stdout, "2\n");
fflush(stdout);

                XTextExtents(fontinfo, hello_string, hello_string_length,
                            &font_direction, &font_ascent, &font_descent,
                            &text_structure);
fprintf(stdout, "3\n");
fflush(stdout);
                XGetWindowAttributes(display, frame_window[screen_ind], &window_attributes);
fprintf(stdout, "4\n");
fflush(stdout);
                text_x = (window_attributes.width - text_structure.width)/2;
                text_y = (window_attributes.height -
                          (text_structure.ascent+text_structure.descent))/2;
fprintf(stdout, "5\n");
fflush(stdout);
                XDrawString(display, frame_window[screen_ind], graphical_context, text_x, text_y, hello_string, hello_string_length);
fprintf(stdout, "6\n");
fflush(stdout);
                break;
            }
            default:
                break;
        }
    }
    return(0);
}

If I loop the fontinfo and graphical context portion like the rest, I get a Bus Error.

I can run the single version on each of the different screens one at a time, just not all three in one program.

Help!

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images