[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-xorg
Subject:    Primary Monitor is 0?
From:       "kaifeng.zhu" <cafeeee () gmail ! com>
Date:       2012-12-25 12:37:20
Message-ID: CAHetZSnN9h09VHHeciEx0moGKDawRg3eO2H49hQmhN+Cyrta+Q () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hello,

I'm not sure that is the correct mailing list to ask this question, but I
didn't find an answer anywhere on the web.

I have a laptop running Ubuntu 11.04 connected to an external Dell monitor.
When I was calling XRRGetOutputPrimary, it returned me the primary monitor
is 0. My code snippet is simple:
    static void test1()
    {
        Display *dpy = XOpenDisplay(NULL);
        int screen_count = ScreenCount(dpy);
        int screen = DefaultScreen(dpy);
        Window root = RootWindow(dpy, screen);
        RROutput primary = XRRGetOutputPrimary(dpy, root);
        printf("Primary = %ld\n", primary);
    }

That seems not a big trouble so I just run command 'xrandr --output LVDS1
--primary' to set the primary monitor. But after that when I'm trying to
create a window to maximize the window to both my monitors, it failed. The
window only occupy part of the external monitor, with the window size
equals to the size of the laptop owned monitor (my external monitor has
higher resolution than my laptop owned monitor).
    static void test2()
    {
        Display *dpy = XOpenDisplay(NULL);
     const Atom _NET_WM_FULLSCREEN_MONITORS = XInternAtom(dpy,
"_NET_WM_FULLSCREEN_MONITORS", False);
    const Atom _NET_WM_STATE = XInternAtom(dpy, "_NET_WM_STATE", False);
    const Atom _NET_WM_STATE_FULLSCREEN = XInternAtom(dpy,
"_NET_WM_STATE_FULLSCREEN", False);

    XSetWindowAttributes attrs;
    attrs.event_mask = StructureNotifyMask | PropertyChangeMask;
    Window wnd = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, 100, 100,
0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask |
CWBorderPixel, &attrs);

    XMapWindow(dpy, wnd);

     {
    XClientMessageEvent ev;
                memset(&ev, 0, sizeof(ev));

    ev.type = ClientMessage;
    ev.window = wnd;
    ev.message_type = _NET_WM_STATE;
     ev.format = 32;
    ev.data.l[0] = 1;
    ev.data.l[1] = _NET_WM_STATE_FULLSCREEN;
     ev.data.l[2] = 0;
    ev.data.l[3] = 1;
    ev.data.l[4] = 0;

    XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureNotifyMask |
SubstructureRedirectMask, (XEvent*)&ev);
     }

     {
    XClientMessageEvent ev;
            memset(&ev, 0, sizeof(ev));

            int snumber = 0;
            XineramaScreenInfo *sinfo = XineramaQueryScreens(dpy, &snumber);
            int top = 0, bottom = 0, left = 0, right = 0;
            for (int i=1; i<snumber; ++i)
            {
                if (sinfo[i].x_org < sinfo[left].x_org)
                    left = i;
                if (sinfo[i].y_org < sinfo[top].y_org)
                    top = i;
                if (sinfo[i].x_org + sinfo[i].width > sinfo[right].x_org +
sinfo[right].width)
                    right = i;
                if (sinfo[i].y_org + sinfo[i].height > sinfo[bottom].y_org
+ sinfo[bottom].height)
                    bottom = i;
            }
            printf("top = %d, bottom = %d, left = %d, right = %d\n",
                top, bottom, left, right);

    ev.type = ClientMessage;
    ev.window = wnd;
    ev.message_type = _NET_WM_FULLSCREEN_MONITORS;
     ev.format = 32;
    ev.data.l[0] = top;
    ev.data.l[1] = bottom;
    ev.data.l[2] = left;
    ev.data.l[3] = right;
    ev.data.l[4] = 1;

    XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureNotifyMask |
SubstructureRedirectMask, (XEvent*)&ev);
     }

        XSync(dpy, False);
        sleep(10);

        {
            int black = BlackPixel(dpy, DefaultScreen(dpy));
            int white = WhitePixel(dpy, DefaultScreen(dpy));
            GC gc = XCreateGC(dpy, wnd, 0, NULL);
            XSetForeground(dpy, gc, white);
            XFillRectangle(dpy, wnd, gc, 0, 0, 4000, 1200);
            XFlush(dpy);
        }

        sleep(10);
    }


Are my steps wrong to create full screen window span to multiple monitors?
Any help or pointers will be greatly appreciated.

Best Regards,
Kaifeng

[Attachment #5 (text/html)]

<div dir="ltr">Hello,<div><br></div><div style>I&#39;m not sure that is the correct \
mailing list to ask this question, but I didn&#39;t find an answer anywhere on the \
web.</div><div style><br></div><div style>I have a laptop running Ubuntu 11.04 \
connected to an external Dell monitor. When I was calling XRRGetOutputPrimary, it \
returned me the primary monitor is 0. My code snippet is simple:</div> <div \
style><div>    static void test1()</div><div>    {</div><div>        Display *dpy = \
XOpenDisplay(NULL);</div><div>        int screen_count = ScreenCount(dpy);</div><div> \
int screen = DefaultScreen(dpy);<br></div> <div>        Window root = RootWindow(dpy, \
screen);</div><div>        RROutput primary = XRRGetOutputPrimary(dpy, \
root);</div><div>        printf(&quot;Primary = %ld\n&quot;, primary);<br></div><div> \
}</div><div><br></div> <div style>That seems not a big trouble so I just run command \
&#39;xrandr --output LVDS1 --primary&#39; to set the primary monitor. But after that \
when I&#39;m trying to create a window to maximize the window to both my monitors, it \
failed. The window only occupy part of the external monitor, with the window size \
equals to the size of the laptop owned monitor (my external monitor has higher \
resolution than my laptop owned monitor).</div> <div style><div>    static void \
test2()</div><div>    {</div><div>        Display *dpy = \
XOpenDisplay(NULL);</div><div>    <span class="" \
style="white-space:pre">	</span>const Atom _NET_WM_FULLSCREEN_MONITORS = \
XInternAtom(dpy, &quot;_NET_WM_FULLSCREEN_MONITORS&quot;, False);<br> </div><div>    \
<span class="" style="white-space:pre">	</span>const Atom _NET_WM_STATE = \
XInternAtom(dpy, &quot;_NET_WM_STATE&quot;, False);</div><div>    <span class="" \
style="white-space:pre">	</span>const Atom _NET_WM_STATE_FULLSCREEN = \
XInternAtom(dpy, &quot;_NET_WM_STATE_FULLSCREEN&quot;, False);</div> <div>    \
<br></div><div>    <span class="" \
style="white-space:pre">	</span>XSetWindowAttributes attrs;</div><div>    <span \
class="" style="white-space:pre">	</span>attrs.event_mask = StructureNotifyMask | \
PropertyChangeMask;</div> <div>    <span class="" \
style="white-space:pre">	</span>Window wnd = XCreateWindow(dpy, \
DefaultRootWindow(dpy), 0, 0, 100, 100, 0, CopyFromParent, InputOutput, \
CopyFromParent, CWEventMask | CWBorderPixel, &amp;attrs);</div> <div>    \
<br></div><div>    <span class="" style="white-space:pre">	</span>XMapWindow(dpy, \
wnd);</div><div>    <br></div><div>    <span class="" \
style="white-space:pre">	</span>{<br></div><div>    <span class="" \
style="white-space:pre">		</span>XClientMessageEvent ev;</div> <div>                \
memset(&amp;ev, 0, sizeof(ev));</div><div>    </div><div>    <span class="" \
style="white-space:pre">		</span>ev.type = ClientMessage;</div><div>    <span \
class="" style="white-space:pre">		</span>ev.window = wnd;</div> <div>    <span \
class="" style="white-space:pre">		</span>ev.message_type = _NET_WM_STATE;</div><div> \
<span class="" style="white-space:pre">		</span>ev.format = 32;<br></div><div>    \
<span class="" style="white-space:pre">		</span>ev.data.l[0] = 1;</div> <div>    \
<span class="" style="white-space:pre">		</span>ev.data.l[1] = \
_NET_WM_STATE_FULLSCREEN;</div><div>    <span class="" \
style="white-space:pre">		</span>ev.data.l[2] = 0;<br></div><div>    <span class="" \
style="white-space:pre">		</span>ev.data.l[3] = 1;</div> <div>    <span class="" \
style="white-space:pre">		</span>ev.data.l[4] = 0;</div><div>    </div><div>    <span \
class="" style="white-space:pre">		</span>XSendEvent(dpy, DefaultRootWindow(dpy), \
False, SubstructureNotifyMask | SubstructureRedirectMask, (XEvent*)&amp;ev);</div> \
<div>    <span class="" style="white-space:pre">	</span>}<br></div><div>    \
</div><div>    <span class="" style="white-space:pre">	</span>{<br></div><div>    \
<span class="" style="white-space:pre">	    </span>XClientMessageEvent ev;</div> \
<div>            memset(&amp;ev, 0, sizeof(ev));</div><div>    </div><div>            \
int snumber = 0;</div><div>            XineramaScreenInfo *sinfo = \
XineramaQueryScreens(dpy, &amp;snumber);</div><div>            int top = 0, bottom = \
0, left = 0, right = 0;</div> <div>            for (int i=1; i&lt;snumber; \
++i)</div><div>            {</div><div>                if (sinfo[i].x_org &lt; \
sinfo[left].x_org)</div><div>                    left = i;</div><div>                \
if (sinfo[i].y_org &lt; sinfo[top].y_org)</div> <div>                    top = \
i;</div><div>                if (sinfo[i].x_org + sinfo[i].width &gt; \
sinfo[right].x_org + sinfo[right].width)</div><div>                    right = \
i;</div><div>                if (sinfo[i].y_org + sinfo[i].height &gt; \
sinfo[bottom].y_org + sinfo[bottom].height)</div> <div>                    bottom = \
i;</div><div>            }</div><div>            printf(&quot;top = %d, bottom = %d, \
left = %d, right = %d\n&quot;,</div><div>                top, bottom, left, \
right);</div><div>    </div> <div>    <span class="" \
style="white-space:pre">		</span>ev.type = ClientMessage;</div><div>    <span \
class="" style="white-space:pre">		</span>ev.window = wnd;</div><div>    <span \
class="" style="white-space:pre">		</span>ev.message_type = \
_NET_WM_FULLSCREEN_MONITORS;</div> <div>    <span class="" \
style="white-space:pre">		</span>ev.format = 32;<br></div><div>    <span class="" \
style="white-space:pre">		</span>ev.data.l[0] = top;</div><div>    <span class="" \
style="white-space:pre">		</span>ev.data.l[1] = bottom;</div> <div>    <span class="" \
style="white-space:pre">		</span>ev.data.l[2] = left;</div><div>    <span class="" \
style="white-space:pre">		</span>ev.data.l[3] = right;</div><div>    <span class="" \
style="white-space:pre">		</span>ev.data.l[4] = 1;</div> <div>    </div><div>    \
<span class="" style="white-space:pre">		</span>XSendEvent(dpy, \
DefaultRootWindow(dpy), False, SubstructureNotifyMask | SubstructureRedirectMask, \
(XEvent*)&amp;ev);</div><div>    <span class="" style="white-space:pre">	</span>}<br> \
</div><div><div><div><br></div><div style>        XSync(dpy, False);</div><div>       \
sleep(10);</div></div></div><div><br></div><div><div>        {</div><div>            \
int black = BlackPixel(dpy, DefaultScreen(dpy));</div> <div>            int white = \
WhitePixel(dpy, DefaultScreen(dpy));</div><div>            GC gc = XCreateGC(dpy, \
wnd, 0, NULL);</div><div>            XSetForeground(dpy, gc, white);</div><div>       \
XFillRectangle(dpy, wnd, gc, 0, 0, 4000, 1200);<br> </div><div>            \
XFlush(dpy);</div><div>        }</div><div><br></div><div>        \
sleep(10);</div><div>    }<br></div></div><div><br></div><div><br></div><div \
style>Are my steps wrong to create full screen window span to multiple monitors? Any \
help or pointers will be greatly appreciated.</div> <div style><br></div><div \
style>Best Regards,</div><div style>Kaifeng</div></div></div></div>



_______________________________________________
xorg@lists.x.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.x.org/mailman/listinfo/xorg
Your subscription address: freedesktop-xorg@progressive-comp.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic