Multi head/multi window hello world


 
Thread Tools Search this Thread
Top Forums Programming Multi head/multi window hello world
# 1  
Old 06-09-2015
Multi head/multi window hello world

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!
# 2  
Old 06-09-2015
Just asking as i dont speak C[#/+].
0) Is this a GUI or console app?
1) It (to me) looks like you can only adress one screen at the time, due to the if-elif block, you might want to change (or just add) a for ARG loop?

hth
# 3  
Old 06-09-2015
I would say it is a console ap. I need to drive three displays that are nowhere near the systems "console." I decided to force the different heads into specific screens so I do not have to worry about resize events on the main console. That is why I am trying to determine which window the event came from. Just trying to say "hello 1" on the first display and "Hello 2" on the second, etc. I will be taking over the entire display. No real windows/GUI code. Mostly text overlays and blending images.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with reformat single-line multi-fasta into multi-line multi-fasta

Input File: >Seq1 ASDADAFASFASFADGSDGFSDFSDFSDFSDFSDFSDFSDFSDFSDFSDFSD >Seq2 SDASDAQEQWEQeqAdfaasd >Seq3 ASDSALGHIUDFJANCAGPATHLACJHPAUTYNJKG ...... Desired Output File >Seq1 ASDADAFASF ASFADGSDGF SDFSDFSDFS DFSDFSDFSD FSDFSDFSDF SD >Seq2 (4 Replies)
Discussion started by: patrick87
4 Replies

2. UNIX for Dummies Questions & Answers

Multi PHP

Hello I have a CentOS 6.5 PHP version : 5.4 Software : Nginx+Apache PHP handler : fcgi Currently I have php 5.4, however I have some scripts which requires php 5.3. How can I achieve this? PHP selector requires CloudLinux. I do not wish to buy CloudLinux subs Can anyone guide me how can... (1 Reply)
Discussion started by: johnchristy
1 Replies

3. Shell Programming and Scripting

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -... (4 Replies)
Discussion started by: nricardo
4 Replies

4. Shell Programming and Scripting

Multi-line filtering based on multi-line pattern in a file

I have a file with data records separated by multiple equals signs, as below. ========== RECORD 1 ========== RECORD 2 DATA LINE ========== RECORD 3 ========== RECORD 4 DATA LINE ========== RECORD 5 DATA LINE ========== I need to filter out all data from this file where the... (2 Replies)
Discussion started by: Finja
2 Replies

5. Red Hat

Multi OS option

Hi, We will purchase redhat enterprise WS. We want to use Windows and Redhat in same machine. For this purpose , should we buy Redhat with Multi OS option? Or Is it just for virtualization..? (I couldnt be sure) Regards... (3 Replies)
Discussion started by: titanic
3 Replies

6. Shell Programming and Scripting

Multi record

I have fixed width source file data look like this, J510111112222 J5102ABCD J510133334444 J5102EFGH I want to make this like 11112222J510111112222 11112222J5102ABCD 33334444J510133334444 33334444J5102EFGH Bolded is the record type. Thanks for help. (8 Replies)
Discussion started by: saravanamr
8 Replies

7. Programming

Multi threading?

I am not sure if multi threading is the correct term, but here is what I am trying to do. I have a while loop that displays the number 1, pauses, displays the number 2, pauses , displays the number 3 ad infinitum. It just keeps counting. While the screen displays the sequence of numbers counting... (4 Replies)
Discussion started by: enuenu
4 Replies

8. UNIX for Dummies Questions & Answers

Multi User Multi Task

Dear Experts Why we always hear that unix operating system is Multi User and Multi task. What does these two means. I have looked at some books and documents but couldn't find aclear explenation. Can we say Windows operating system is also multi user and multi task?? Thanks for your help in... (6 Replies)
Discussion started by: Reza Nazarian
6 Replies

9. Programming

Regarding Multi-Threading

Hi All, Here's my question I have a 385 MB file containing 5,000,000 records. I need to read from the file and load into a table. Initially i thought of doing it in a single thread (execution of a single program) but when calculated accounted 16 hours of time on a standard benchmark. Hence... (5 Replies)
Discussion started by: matrixmadhan
5 Replies

10. UNIX for Dummies Questions & Answers

multi-file multi-edit

Good day! I am trying to learn how to use the "sed" editor, to perform multiple edits on multiple files in multiple directories. I have one script that tries to call up each file and process it according to the edits listed in a second script. I am using a small input text to test these, at... (12 Replies)
Discussion started by: kielitaide
12 Replies
Login or Register to Ask a Question