Tk Source Code

Check-in [49d4d5d6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[Bug 533519]: Window placement with multiple screens
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 49d4d5d62bfa2117dad916bd483368b7fcb4edcb
User & Date: jan.nijtmans 2012-04-29 07:37:15
Original Comment: [Bug 3508771]: Window placement with multiple screens
Context
2012-05-02
11:42
merge-mark check-in: 19cd87b4 user: jan.nijtmans tags: trunk
2012-04-29
08:22
merge trunk check-in: e74e9b0e user: jan.nijtmans tags: jn-web-colors
08:16
merge trunk Closed-Leaf check-in: 1c7e0278 user: jan.nijtmans tags: bug-3512824
07:37
[Bug 533519]: Window placement with multiple screens check-in: 49d4d5d6 user: jan.nijtmans tags: trunk
2012-04-26
14:05
merge trunk Closed-Leaf check-in: e0b7673f user: jan.nijtmans tags: bug-533519
13:48
Ensure that Tk_GetHINSTANCE is defined on OSX. check-in: b6847552 user: dkf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.









1
2
3
4
5
6
7








2012-04-26  Donal K. Fellows  <[email protected]>

	* generic/tkStubInit.c (Tk_GetHINSTANCE): Ensure that this is defined
	for OSX.

2012-04-26  Jan Nijtmans  <[email protected]>

>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2012-04-29  Jan Nijtmans  <[email protected]>

	* library/tk.tcl:    [Bug 3508771]: Window placement with multiple screens
	* generic/tkBind.c:
	* generic/tkFocus.c:
	* generic/tkMenuDraw.c:
	* generic/tkWinWm.c:

2012-04-26  Donal K. Fellows  <[email protected]>

	* generic/tkStubInit.c (Tk_GetHINSTANCE): Ensure that this is defined
	for OSX.

2012-04-26  Jan Nijtmans  <[email protected]>

Changes to generic/tkBind.c.

2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
	    } else {
		string = "??";
	    }
	    goto doString;
	}
	case 'X':
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		Tk_Window tkwin;
		int x, y;
		int width, height;

		number = eventPtr->xkey.x_root;
		tkwin = Tk_IdToWindow(eventPtr->xany.display,
			eventPtr->xany.window);
		if (tkwin != NULL) {
		    Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height);
		    number -= x;
		}
		goto doNumber;
	    }
	    goto doString;
	case 'Y':
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		Tk_Window tkwin;
		int x, y;
		int width, height;

		number = eventPtr->xkey.y_root;
		tkwin = Tk_IdToWindow(eventPtr->xany.display,
			eventPtr->xany.window);
		if (tkwin != NULL) {
		    Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height);
		    number -= y;
		}
		goto doNumber;
	    }
	    goto doString;
	default:
	    numStorage[0] = before[1];
	    numStorage[1] = '\0';
	    string = numStorage;







<
<
<


|

<
<
<
<





<
<
<


|

<
<
<
<







2222
2223
2224
2225
2226
2227
2228



2229
2230
2231
2232




2233
2234
2235
2236
2237



2238
2239
2240
2241




2242
2243
2244
2245
2246
2247
2248
	    } else {
		string = "??";
	    }
	    goto doString;
	}
	case 'X':
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {




		number = eventPtr->xkey.x_root;
		Tk_IdToWindow(eventPtr->xany.display,
			eventPtr->xany.window);




		goto doNumber;
	    }
	    goto doString;
	case 'Y':
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {




		number = eventPtr->xkey.y_root;
		Tk_IdToWindow(eventPtr->xany.display,
			eventPtr->xany.window);




		goto doNumber;
	    }
	    goto doString;
	default:
	    numStorage[0] = before[1];
	    numStorage[1] = '\0';
	    string = numStorage;

Changes to generic/tkFocus.c.

711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
    TkWindow *winPtr,		/* Window that selects an application and a
				 * display. */
    XEvent *eventPtr)		/* X event to redirect (should be KeyPress or
				 * KeyRelease). */
{
    DisplayFocusInfo *displayFocusPtr;
    TkWindow *focusWinPtr;
    int focusX, focusY, vRootX, vRootY, vRootWidth, vRootHeight;

    displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr, winPtr->dispPtr);
    focusWinPtr = displayFocusPtr->focusWinPtr;

    /*
     * The code below is a debugging aid to make sure that dispPtr->focusPtr
     * is kept properly in sync with the "truth", which is the value in







|







711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
    TkWindow *winPtr,		/* Window that selects an application and a
				 * display. */
    XEvent *eventPtr)		/* X event to redirect (should be KeyPress or
				 * KeyRelease). */
{
    DisplayFocusInfo *displayFocusPtr;
    TkWindow *focusWinPtr;
    int focusX, focusY;

    displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr, winPtr->dispPtr);
    focusWinPtr = displayFocusPtr->focusWinPtr;

    /*
     * The code below is a debugging aid to make sure that dispPtr->focusPtr
     * is kept properly in sync with the "truth", which is the value in
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
	 */

	if ((focusWinPtr->display != winPtr->display)
		|| (focusWinPtr->screenNum != winPtr->screenNum)) {
	    eventPtr->xkey.x = -1;
	    eventPtr->xkey.y = -1;
	} else {
	    Tk_GetVRootGeometry((Tk_Window) focusWinPtr, &vRootX, &vRootY,
		    &vRootWidth, &vRootHeight);
	    Tk_GetRootCoords((Tk_Window) focusWinPtr, &focusX, &focusY);
	    eventPtr->xkey.x = eventPtr->xkey.x_root - vRootX - focusX;
	    eventPtr->xkey.y = eventPtr->xkey.y_root - vRootY - focusY;
	}
	eventPtr->xkey.window = focusWinPtr->window;
	return focusWinPtr;
    }

    /*
     * The event doesn't belong to us. Perhaps, due to embedding, it really







<
<

|
|







744
745
746
747
748
749
750


751
752
753
754
755
756
757
758
759
760
	 */

	if ((focusWinPtr->display != winPtr->display)
		|| (focusWinPtr->screenNum != winPtr->screenNum)) {
	    eventPtr->xkey.x = -1;
	    eventPtr->xkey.y = -1;
	} else {


	    Tk_GetRootCoords((Tk_Window) focusWinPtr, &focusX, &focusY);
	    eventPtr->xkey.x = eventPtr->xkey.x_root - focusX;
	    eventPtr->xkey.y = eventPtr->xkey.y_root - focusY;
	}
	eventPtr->xkey.window = focusWinPtr->window;
	return focusWinPtr;
    }

    /*
     * The event doesn't belong to us. Perhaps, due to embedding, it really

Changes to generic/tkMenuDraw.c.

840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
TkPostTearoffMenu(
    Tcl_Interp *interp,		/* The interpreter of the menu */
    TkMenu *menuPtr,		/* The menu we are posting */
    int x, int y)		/* The root X,Y coordinates where we are
				 * posting */
{
    int vRootX, vRootY, vRootWidth, vRootHeight;
    int tmp, result;

    TkActivateMenuEntry(menuPtr, -1);
    TkRecomputeMenu(menuPtr);
    result = TkPostCommand(menuPtr);
    if (result != TCL_OK) {
    	return result;
    }







|







840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
TkPostTearoffMenu(
    Tcl_Interp *interp,		/* The interpreter of the menu */
    TkMenu *menuPtr,		/* The menu we are posting */
    int x, int y)		/* The root X,Y coordinates where we are
				 * posting */
{
    int vRootX, vRootY, vRootWidth, vRootHeight;
    int result;

    TkActivateMenuEntry(menuPtr, -1);
    TkRecomputeMenu(menuPtr);
    result = TkPostCommand(menuPtr);
    if (result != TCL_OK) {
    	return result;
    }
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
     *    (if any) to the real root. Can't get the virtual root from the menu
     *    itself (it will never be seen by the wm) so use its parent instead
     *    (it would be better to have an an option that names a window to use
     *    for this...).
     * 2. The menu may not have been mapped yet, so its current size might be
     *    the default 1x1. To compute how much space it needs, use its
     *    requested size, not its actual size.
     *
     * Note that this code assumes square screen regions and all positive
     * coordinates. This does not work on a Mac with multiple monitors. But
     * then again, Tk has other problems with this.
     */

    Tk_GetVRootGeometry(Tk_Parent(menuPtr->tkwin), &vRootX, &vRootY,
	&vRootWidth, &vRootHeight);
    x += vRootX;
    y += vRootY;
    tmp = WidthOfScreen(Tk_Screen(menuPtr->tkwin))
	- Tk_ReqWidth(menuPtr->tkwin);
    if (x > tmp) {
	x = tmp;
    }
    if (x < 0) {
	x = 0;
    }
    tmp = HeightOfScreen(Tk_Screen(menuPtr->tkwin))
	- Tk_ReqHeight(menuPtr->tkwin);
    if (y > tmp) {
	y = tmp;
    }
    if (y < 0) {
	y = 0;
    }
    Tk_MoveToplevelWindow(menuPtr->tkwin, x, y);
    if (!Tk_IsMapped(menuPtr->tkwin)) {
	Tk_MapWindow(menuPtr->tkwin);
    }
    TkWmRestackToplevel((TkWindow *) menuPtr->tkwin, Above, NULL);
    return TCL_OK;







<
<
<
<




<
<
<
<
|
|

|
|

<
<
|
|

|
|







873
874
875
876
877
878
879




880
881
882
883




884
885
886
887
888
889


890
891
892
893
894
895
896
897
898
899
900
901
     *    (if any) to the real root. Can't get the virtual root from the menu
     *    itself (it will never be seen by the wm) so use its parent instead
     *    (it would be better to have an an option that names a window to use
     *    for this...).
     * 2. The menu may not have been mapped yet, so its current size might be
     *    the default 1x1. To compute how much space it needs, use its
     *    requested size, not its actual size.




     */

    Tk_GetVRootGeometry(Tk_Parent(menuPtr->tkwin), &vRootX, &vRootY,
	&vRootWidth, &vRootHeight);




    if (x > vRootX + vRootWidth) {
	x = vRootX + vRootWidth;
    }
    if (x < vRootX) {
	x = vRootX;
    }


    if (y > vRootY + vRootHeight) {
	y = vRootY + vRootHeight;
    }
    if (y < vRootY) {
	y = vRootY;
    }
    Tk_MoveToplevelWindow(menuPtr->tkwin, x, y);
    if (!Tk_IsMapped(menuPtr->tkwin)) {
	Tk_MapWindow(menuPtr->tkwin);
    }
    TkWmRestackToplevel((TkWindow *) menuPtr->tkwin, Above, NULL);
    return TCL_OK;

Changes to library/tk.tcl.

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
	set y [expr {[winfo rooty $anchor] + \
		([winfo height $anchor]-[winfo reqheight $w])/2}]
    } else {
	set x [expr {([winfo screenwidth $w]-[winfo reqwidth $w])/2}]
	set y [expr {([winfo screenheight $w]-[winfo reqheight $w])/2}]
	set checkBounds 0
    }
    if {[tk windowingsystem] eq "win32"} {
        # Bug 533519: win32 multiple desktops may produce negative geometry.
        set checkBounds 0
    }
    if {$checkBounds} {
	if {$x < [winfo vrootx $w]} {
	    set x [winfo vrootx $w]
	} elseif {$x > ([winfo vrootx $w]+[winfo vrootwidth $w]-[winfo reqwidth $w])} {
	    set x [expr {[winfo vrootx $w]+[winfo vrootwidth $w]-[winfo reqwidth $w]}]
	}
	if {$y < [winfo vrooty $w]} {







<
<
<
<







107
108
109
110
111
112
113




114
115
116
117
118
119
120
	set y [expr {[winfo rooty $anchor] + \
		([winfo height $anchor]-[winfo reqheight $w])/2}]
    } else {
	set x [expr {([winfo screenwidth $w]-[winfo reqwidth $w])/2}]
	set y [expr {([winfo screenheight $w]-[winfo reqheight $w])/2}]
	set checkBounds 0
    }




    if {$checkBounds} {
	if {$x < [winfo vrootx $w]} {
	    set x [winfo vrootx $w]
	} elseif {$x > ([winfo vrootx $w]+[winfo vrootwidth $w]-[winfo reqwidth $w])} {
	    set x [expr {[winfo vrootx $w]+[winfo vrootwidth $w]-[winfo reqwidth $w]}]
	}
	if {$y < [winfo vrooty $w]} {

Changes to win/tkWinWm.c.

6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
    Tk_Window tkwin,		/* Window whose virtual root is to be
				 * queried. */
    int *xPtr, int *yPtr,	/* Store x and y offsets of virtual root
				 * here. */
    int *widthPtr, int *heightPtr)
				/* Store dimensions of virtual root here. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;

    /*
     * XXX: This is not correct for multiple monitors. There may be many
     * changes required to get this right, and it may effect existing
     * applications that don't consider possible <0 vroot. See
     * http://msdn.microsoft.com/library/en-us/gdi/monitor_3lrn.asp for more
     * info.
     */

    *xPtr = 0;
    *yPtr = 0;
    *widthPtr = DisplayWidth(winPtr->display, winPtr->screenNum);
    *heightPtr = DisplayHeight(winPtr->display, winPtr->screenNum);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MoveToplevelWindow --
 *







<
<
<
<
<
<
<
<
<
<
|
|
|
|







6397
6398
6399
6400
6401
6402
6403










6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
    Tk_Window tkwin,		/* Window whose virtual root is to be
				 * queried. */
    int *xPtr, int *yPtr,	/* Store x and y offsets of virtual root
				 * here. */
    int *widthPtr, int *heightPtr)
				/* Store dimensions of virtual root here. */
{










    *xPtr = GetSystemMetrics(SM_XVIRTUALSCREEN);
    *yPtr = GetSystemMetrics(SM_YVIRTUALSCREEN);
    *widthPtr = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    *heightPtr = GetSystemMetrics(SM_CYVIRTUALSCREEN);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MoveToplevelWindow --
 *