Wm(3pm)
π NAME π
Tk::Wm β Communicate with window manager.
yep that's it, that's the whole job description π this is the Wm(3pm) page from the User Contributed Perl Documentation, and it's literally just your hotline to the window manager. slay.
β¨ SYNOPSIS β¨
$toplevel->method(?args?)
π¦ DESCRIPTION π¦
okay so bestie, the wm methods are how you actually talk to window managers β controlling stuff like the title for a window, its geometry, or the increments in terms of which it may be resized. the wm methods can take any of a number of different forms, depending on the particular method argument. every single one of those forms expects $toplevel, and $toplevel must be a top-level window object. no exceptions, no cap. π
The legal forms for the wm methods are:
πΈ $toplevel->aspect(?minNumer minDenom maxNumer maxDenom?)
If minNumer, minDenom, maxNumer and maxDenom are all specified, then they get passed straight to the window manager and the window manager should use them to enforce a range of acceptable aspect ratios for $toplevel. the aspect ratio of $toplevel (width/length) will be constrained to lie between minNumer/minDenom and maxNumer/maxDenom. If minNumer etc. are all specified as empty strings, then any existing aspect ratio restrictions are removed β bye π. If minNumer etc. are specified, then the method returns an empty string. Otherwise, it returns an array containing four elements, which are the current values of minNumer, minDenom, maxNumer and maxDenom (and if no aspect restrictions are in effect, then an empty string is returned instead).
π
$widget->attributes( ?args? );
This subcommand returns or sets platform specific attributes associated with a window. very "it depends on your OS" energy.
$widget->attributes;β Returns a list of the platform specific flags and their values.$widget->attributes( ?option? );β Returns the value for the specific option.$widget->attributes( ?option value option value...? );β Sets one or more of the values. The values are as follows:- On Windows,
-disabledgets or sets whether the window is in a disabled state.-toolwindowgets or sets the style of the window to toolwindow (as defined in the MSDN).-topmostgets or sets whether this is a topmost window (displays above all other windows). stacking, iconic. - On Macintosh, there are currently no special attribute values. π
- On Unix, there are currently no special attribute values. π
- On Windows,
π«Ά $toplevel->client(?name?)
If name is specified, this method stores name (which should be the name of the host on which the application is executing) in $toplevel's WM_CLIENT_MACHINE property for use by the window manager or session manager. the method returns an empty string in this case. If name isn't specified, the method returns the last name set in a client method for $toplevel. If name is specified as an empty string, the method deletes the WM_CLIENT_MACHINE property from $toplevel. clean slate, we love that β¨
π $toplevel->colormapwindows(?windowList?)
This method is used to manipulate the WM_COLORMAP_WINDOWS property, which provides information to the window managers about windows that have private colormaps. If windowList isn't specified, the method returns a list whose elements are the names of the windows in the WM_COLORMAP_WINDOWS property. If windowList is specified, it consists of a list of widgets; the method overwrites the WM_COLORMAP_WINDOWS property with the given windows and returns an empty string.
The WM_COLORMAP_WINDOWS property should normally contain a list of the internal windows within $toplevel whose colormaps differ from their parents. the order of the windows in the property indicates a priority order: the window manager will attempt to install as many colormaps as possible from the head of this list when $widget gets the colormap focus.
If $widget is not included among the windows in windowList, Tk implicitly adds it at the end of the WM_COLORMAP_WINDOWS property, so that its colormap is lowest in priority. If $widget->colormapwindows is not invoked, Tk will automatically set the property for each top-level window to all the internal windows whose colormaps differ from their parents, followed by the top-level itself; the order of the internal windows is undefined. See the ICCCM documentation for more information on the WM_COLORMAP_WINDOWS property. π
π $toplevel->command(?value?)
If value is specified, this method stores value in $toplevel's WM_COMMAND property for use by the window manager or session manager and returns an empty string. value must have proper list structure; the elements should contain the words of the command used to invoke the application. If value isn't specified then the method returns the last value set in a command method for $toplevel. If value is specified as an empty string, the method deletes the WM_COMMAND property from $toplevel.
π§ $toplevel->deiconify
Arrange for $toplevel to be displayed in normal (non-iconified) form. this is done by mapping the window. If the window has never been mapped then this method will not map the window, but it will ensure that when the window is first mapped it will be displayed in de-iconified form. Returns an empty string. come back to me bestie π₯Ί
β $toplevel->focusmodel(?active|passive?)
If active or passive is supplied as an optional argument to the method, then it specifies the focus model for $toplevel. In this case the method returns an empty string. If no additional argument is supplied, then the method returns the current focus model for $toplevel.
An active focus model means that $toplevel will claim the input focus for itself or its descendants, even at times when the focus is currently in some other application. Passive means that $toplevel will never claim the focus for itself: the window manager should give the focus to $toplevel at appropriate times. However, once the focus has been given to $toplevel or one of its descendants, the application may re-assign the focus among $toplevel's descendants.
The focus model defaults to passive, and Tk's focus method assumes a passive model of focusing. main character energy is optional, apparently π
π $toplevel->frame
If $widget has been reparented by the window manager into a decorative frame, the method returns the platform specific window identifier for the outermost frame that contains $toplevel (the window whose parent is the root or virtual root). If $toplevel hasn't been reparented by the window manager then the method returns the platform specific window identifier for $toplevel.
π $toplevel->geometry(?newGeometry?)
If newGeometry is specified, then the geometry of $toplevel is changed and an empty string is returned. Otherwise the current geometry for $toplevel is returned (this is the most recent geometry specified either by manual resizing or in a geometry method).
newGeometry has the form =widthxheight+-x+-y, where any of =, widthxheight, or +-x+-y may be omitted. width and height are positive integers specifying the desired dimensions of $toplevel. If $toplevel is gridded (see "GRIDDED GEOMETRY MANAGEMENT" below) then the dimensions are specified in grid units; otherwise they are specified in pixel units.
x and y specify the desired location of $toplevel on the screen, in pixels. If x is preceded by +, it specifies the number of pixels between the left edge of the screen and the left edge of $toplevel's border; if preceded by - then x specifies the number of pixels between the right edge of the screen and the right edge of $toplevel's border. If y is preceded by + then it specifies the number of pixels between the top of the screen and the top of $toplevel's border; if y is preceded by - then it specifies the number of pixels between the bottom of $toplevel's border and the bottom of the screen.
If newGeometry is specified as an empty string then any existing user-specified geometry for $toplevel is cancelled, and the window will revert to the size requested internally by its widgets. reset era π«§
π₯ $toplevel->wmGrid(?baseWidth,baseHeight,widthInc,heightInc?)
This method indicates that $toplevel is to be managed as a gridded window. It also specifies the relationship between grid units and pixel units. baseWidth and baseHeight specify the number of grid units corresponding to the pixel dimensions requested internally by $toplevel using Tk_GeometryRequest. widthInc and heightInc specify the number of pixels in each horizontal and vertical grid unit.
These four values determine a range of acceptable sizes for $toplevel, corresponding to grid-based widths and heights that are non-negative integers. Tk will pass this information to the window manager; during manual resizing, the window manager will restrict the window's size to one of these acceptable sizes. Furthermore, during manual resizing the window manager will display the window's current size in terms of grid units rather than pixels.
If baseWidth etc. are all specified as empty strings, then $toplevel will no longer be managed as a gridded window. If baseWidth etc. are specified then the return value is an empty string. Otherwise the return value is an array containing four elements corresponding to the current baseWidth, baseHeight, widthInc and heightInc; if $toplevel is not currently gridded, then an empty string is returned.
Note: this command should not be needed very often, since theTk_SetGridlibrary procedure and the-setgridoption provide easier access to the same functionality. lowkey just use those π
π· $toplevel->group(?$widget?)
If $widget is specified, it is the the leader of a group of related windows. the window manager may use this information, for example, to unmap all of the windows in a group when the group's leader is iconified. $widget may be specified as an empty string to remove $toplevel from any group association. If $widget is specified then the method returns an empty string; otherwise it returns the $toplevel's current group leader, or an empty string if $toplevel isn't part of any group. found family, but for windows π«Ά
$toplevel->iconbitmap(?bitmap?)β okay bestie, so ifbitmapis specified, it names a bitmap in the standard forms accepted by Tk (peep theTk_GetBitmapdocumentation for the details, iykyk). This black and white bitmap is passed to the window manager to be displayed in$toplevel's icon, and the method returns an empty string. If an empty string is specified forbitmap, then any current icon bitmap or image is cancelled for$toplevel. Ifbitmapis specified then the method returns an empty string. Otherwise it returns the name of the current icon bitmap associated with$toplevel, or an empty string if$toplevelhas no icon bitmap. π$toplevel->iconifyβ arrange for$toplevelto be iconified. If$toplevelhasn't yet been mapped for the first time, this method will arrange for it to appear in the iconified state when it is eventually mapped. β¨$toplevel->iconimage(?image?)β ifimageis specified, then it names a normal Tk image. This image is rendered into a private coloured bitmap which is passed to the window manager to be displayed in$toplevel's icon, and the method returns an empty string. If an empty string is specified forimage, then any current icon bitmap or image is cancelled for$toplevel. Ifimageis specified then the method returns an empty string. Otherwise it returns the name of the current icon image associated with$toplevel, or an empty string if$toplevelhas no icon image. The private pixmap is not pre-cleared so images which are partly "transparent" display rubbish in their transparent parts. π- The sizes of images that can be used as icons in this manner are platform dependent. On Win32 this sets the "large" icon, which should be
32x32, it will automatically be scaled down to16x16for use as a small icon.
- The sizes of images that can be used as icons in this manner are platform dependent. On Win32 this sets the "large" icon, which should be
$toplevel->iconmask(?bitmap?)β ifbitmapis specified, then it names a bitmap in the standard forms accepted by Tk (see theTk_GetBitmapdocumentation for details). This bitmap is passed to the window manager to be used as a mask in conjunction with theiconbitmapoption: where the mask has zeroes no icon will be displayed; where it has ones, the bits from the icon bitmap will be displayed. If an empty string is specified forbitmapthen any current icon mask is cancelled for$toplevel(this is equivalent to specifying a bitmap of all ones). Ifbitmapis specified then the method returns an empty string. Otherwise it returns the name of the current icon mask associated with$toplevel, or an empty string if no mask is in effect.$toplevel->iconname(?newName?)β ifnewNameis specified, then it is passed to the window manager; the window manager should displaynewNameinside the icon associated with$toplevel. In this case an empty string is returned as result. IfnewNameisn't specified then the method returns the current icon name for$toplevel, or an empty string if no icon name has been specified (in this case the window manager will normally display the window's title, as specified with thetitlemethod).$toplevel->iconphoto(?-default? image1 ?image2 ...?)β sets the titlebar icon for window based on the named photo images. If-defaultis specified, this is applied to all future created toplevels as well. The data in the images is taken as a snapshot at the time of invocation. If the images are later changed, this is not reflected to the titlebar icons. Multiple images are accepted to allow different images sizes (eg,16x16and32x32) to be provided. The window manager may scale provided icons to an appropriate size.- On Windows, the images are packed into a Windows icon structure. This will override an ico specified to
wm iconbitmap, and vice versa. [NOTE: This is not implemented yet!] - On X, the images are arranged into the
_NET_WM_ICONX property, which most modern window managers support. Awm iconbitmapmay exist simultaneously. It is recommended to use not more than 2 icons, placing the larger icon first. - On Macintosh, this is currently does nothing.
- On Windows, the images are packed into a Windows icon structure. This will override an ico specified to
$toplevel->iconposition(?x y?)β ifxandyare specified, they are passed to the window manager as a hint about where to position the icon for$toplevel. In this case an empty string is returned. Ifxandyare specified as empty strings then any existing icon position hint is cancelled. If neitherxnoryis specified, then the method returns a array containing two values, which are the current icon position hints (if no hints are in effect then an empty string is returned).$toplevel->iconwindow(?$widget?)β if$widgetis specified, it is a window to use as icon for$toplevel: when$toplevelis iconified then$widgetwill be mapped to serve as icon, and when$toplevelis de-iconified then$widgetwill be unmapped again. If$widgetis specified as an empty string then any existing icon window association for$toplevelwill be cancelled. If the$widgetargument is specified then an empty string is returned. Otherwise the method returns the current icon window for$toplevel, or an empty string if there is no icon window currently specified for$toplevel. Button press events are disabled for$toplevelas long as it is an icon window; this is needed in order to allow window managers to ``own'' those events. Note: not all window managers support the notion of an icon window.$toplevel->maxsize(?width,height?)β ifwidthandheightare specified, they give the maximum permissible dimensions for$toplevel. For gridded windows the dimensions are specified in grid units; otherwise they are specified in pixel units. The window manager will restrict the window's dimensions to be less than or equal towidthandheight. Ifwidthandheightare specified, then the method returns an empty string. Otherwise it returns a array with two elements, which are the maximum width and height currently in effect. The maximum size defaults to the size of the screen. If resizing has been disabled with theresizablemethod, then this method has no effect. See the sections on geometry management below for more information.$toplevel->minsize(?width,height?)β ifwidthandheightare specified, they give the minimum permissible dimensions for$toplevel. For gridded windows the dimensions are specified in grid units; otherwise they are specified in pixel units. The window manager will restrict the window's dimensions to be greater than or equal towidthandheight. Ifwidthandheightare specified, then the method returns an empty string. Otherwise it returns a array with two elements, which are the minimum width and height currently in effect. The minimum size defaults to one pixel in each dimension. If resizing has been disabled with theresizablemethod, then this method has no effect. See the sections on geometry management below for more information.$toplevel->overrideredirect(?boolean?)β ifbooleanis specified, it must have a proper boolean form and the override-redirect flag for$toplevelis set to that value. Ifbooleanis not specified then1or0is returned to indicate whether or not the override-redirect flag is currently set for$toplevel. Setting the override-redirect flag for a window causes it to be ignored by the window manager; among other things, this means that the window will not be reparented from the root window into a decorative frame and the user will not be able to manipulate the window using the normal window manager mechanisms.$toplevel->positionfrom(?who?)β ifwhois specified, it must be eitherprogramoruser, or an abbreviation of one of these two. It indicates whether$toplevel's current position was requested by the program or by the user. Many window managers ignore program-requested initial positions and ask the user to manually position the window; ifuseris specified then the window manager should position the window at the given place without asking the user for assistance. Ifwhois specified as an empty string, then the current position source is cancelled. Ifwhois specified, then the method returns an empty string. Otherwise it returnsuseror$widgetto indicate the source of the window's current position, or an empty string if no source has been specified yet. Most window managers interpret ``no source'' as equivalent toprogram. Tk will automatically set the position source touserwhen a geometry method is invoked, unless the source has been set explicitly toprogram.$toplevel->protocol(?name?,?callback?)β this method is used to manage window manager protocols such asWM_DELETE_WINDOW.Nameis the name of an atom corresponding to a window manager protocol, such asWM_DELETE_WINDOWorWM_SAVE_YOURSELForWM_TAKE_FOCUS. If bothnameandcallbackare specified, thencallbackis associated with the protocol specified byname.Namewill be added to$toplevel'sWM_PROTOCOLSproperty to tell the window manager that the application has a protocol handler forname, andcallbackwill be invoked in the future whenever the window manager sends a message to the client for that protocol. In this case the method returns an empty string. Ifnameis specified butcallbackisn't, then the current callback fornameis returned, or an empty string if there is no handler defined forname. Ifcallbackis specified as an empty string then the current handler fornameis deleted and it is removed from theWM_PROTOCOLSproperty on$toplevel; an empty string is returned. Lastly, if neithernamenorcallbackis specified, the method returns a list of all the protocols for which handlers are currently defined for$toplevel.
Tk always defines a protocol handler forWM_DELETE_WINDOW, even if you haven't asked for one withprotocol. If aWM_DELETE_WINDOWmessage arrives when you haven't defined a handler, then Tk handles the message by destroying the window for which it was received.
$toplevel->resizable(?width,height?) πͺβ¨
okay so this one decides whether your bestie (the user) is allowed to grab the window edge and drag it around. if width and height are given, they're boolean values saying whether the width and height of $toplevel can be changed by the user β and when you pass them, the method hands back an empty string, no drama. if you leave width and height out, you get a list of two 0/1 elements telling you whether the width and height of $toplevel are currently resizable. by default? windows are resizable in both dimensions π
. if resizing is disabled, the window's size becomes whatever it was from the most recent interactive resize or geometry method β and if that never happened, the window's natural size gets used instead. iconic behavior, fr fr.
$toplevel->sizefrom(?who?) π΅οΈβοΈ
if who is specified it has to be either program or user, or an abbreviation of one of those two β no third option bestie, it's giving binary. it says whether $toplevel's current size was requested by the program or by the user. some window managers are soooo stubborn and straight-up ignore program-requested sizes, making the user manually size the window; but if user is specified, the window manager should give the window its specified size without asking the user for help π«Ά. if who is an empty string, the current size source gets cancelled. if who is specified at all, the method returns an empty string. otherwise it returns user or $widget to show the source of the window's current size, or an empty string if no source has been specified yet. most window managers interpret "no source" as equivalent to program. noted π.
$toplevel->stackorder( ?isabove|isbelow $toplevel? ); π₯
the stackorder command returns a list of toplevel windows in stacking order, from lowest to highest. when a single toplevel window is passed, the returned list recursively includes all of the window's children that are toplevels. only those toplevels that are currently mapped to the screen are returned β the rest are lowkey ghosts π». the stackorder command can also be used to figure out if one toplevel is positioned above or below a second toplevel. when two window arguments separated by either isabove or isbelow are passed, a boolean result tells you whether or not the first window is currently above or below the second window in the stacking order. main character energy, always on top π.
$toplevel->state(?newstate?) π¦
if newstate is specified, the window gets set to the new state; otherwise it returns the current state of $toplevel, which is one of: normal, iconic, withdrawn, icon, or (Windows only) zoomed. the difference between iconic and icon is that iconic refers to a window that has been iconified (e.g., with the iconify method) while icon refers to a window whose only purpose is to serve as the icon for some other window (via the iconwindow method). the icon state cannot be set β nope, that one's off-limits, no cap π«.
$toplevel->title(?string?) π¬
if string is specified, it gets passed to the window manager for use as the title for $toplevel (the window manager should display this string in $toplevel's title bar). in that case the method returns an empty string. if string isn't specified, the method returns the current title for the $toplevel. the title for a window defaults to its name. put it on a cute little name tag π.
$toplevel->transient(?master?) π»
if master is specified, the window manager is informed that $toplevel is a transient window (e.g. a pull-down menu) working on behalf of master (where master is a top-level window). some window managers will use this info to manage $toplevel specially β¨. if master is an empty string then $toplevel is marked as not being a transient window any more β it's independent now, growth era π±. if master is specified, the method returns an empty string. otherwise the method returns the path name of $toplevel's current master, or an empty string if $toplevel isn't currently a transient window.
$toplevel->withdraw π
arranges for $toplevel to be withdrawn from the screen. this causes the window to be unmapped and forgotten about by the window manager β like, memory-holed by the WM. if the window has never been mapped, then this method causes the window to be mapped in the withdrawn state. not all window managers appear to know how to handle windows that are mapped in the withdrawn state.
β οΈ Note: it sometimes seems to be necessary to withdraw a window and then re-map it (e.g. withdeiconify) to get some window managers to pay attention to changes in window attributes such asgroup. it's giving "have you tried turning it off and on again" π
$toplevel->wrapper π
returns a list of two elements: the window id of the wrapper window in which Tk has placed $toplevel, and the height of the menu bar. the id is the one by which window manager will know $toplevel, and so is appropriate place to add X properties. the menu height is only returned on X. on Windows, this value is always zero. two little gifts, one's sometimes empty π«Ά.
β¨ ICON SIZES β¨ πΌοΈ
the sizes of bitmaps/images that can be used as icons in this manner are platform and window manager dependent. Unix window managers are typically more tolerant than Win32. it is possible that coloured "iconimage" icons may cause problems on some X window managers β drama potential π
.
- Win32 β
"iconimage"and"iconbitmap"set the"large"icon, which should be 32x32, it will automatically be scaled down to 16x16 for use as a small icon. Win32 ignores"iconwin"requests. - KDE's
"kwm"β accepts coloured"iconimage"and black and white"iconbitmap"but will scale either to a small (14x14?) icon. Kwm ignores"iconwin". - Sun's
"olwm"or"olvwm"β honours"iconwin"which will override"iconimage"or"iconbitmap". coloured images work. - Sun's CDE window manager β coloured images work. ...
π GEOMETRY MANAGEMENT π π
by default a top-level window appears on the screen in its natural size, which is the one determined internally by its widgets and geometry managers. if the natural size of a top-level window changes, then the window's size changes to match. a top-level window can be given a size other than its natural size in two ways:
- the user can resize the window manually using the facilities of the window manager, such as resize handles ποΈ.
- the application can request a particular size for a top-level window using the
geometrymethod π.
these two cases are handled identically by Tk; in either case, the requested size overrides the natural size. you can return the window to its natural by invoking geometry with an empty geometry string. bye pixel-perfect era, hello natural beauty πΈ.
normally a top-level window can have any size from one pixel in each dimension up to the size of its screen. however, you can use the minsize and maxsize methods to limit the range of allowable sizes. the range set by minsize and maxsize applies to all forms of resizing, including the window's natural size as well as manual resizes and the geometry method. you can also use the method resizable to completely disable interactive resizing in one or both dimensions. boundaries bestie, we love them π
.
π¦ GRIDDED GEOMETRY MANAGEMENT π¦ π²
gridded geometry management occurs when one of the widgets of an application supports a range of useful sizes. this occurs, for example, in a text editor where the scrollbars, menus, and other adornments are fixed in size but the edit widget can support any number of lines of text or characters per line. in this case, it is usually desirable to let the user specify the number of lines or characters-per-line, either with the geometry method or by interactively resizing the window. in the case of text, and in other interesting cases also, only discrete sizes of the window make sense, such as integral numbers of lines and characters-per-line; arbitrary pixel sizes are not useful. pixels? not the vibe π«.
gridded geometry management provides support for this kind of application. Tk (and the window manager) assume that there is a grid of some sort within the application and that the application should be resized in terms of grid units rather than pixels. gridded geometry management is typically invoked by turning on the setGrid option for a widget; it can also be invoked with the wmGrid method or by calling Tk_SetGrid. in each of these approaches the particular widget (or sometimes code in the application as a whole) specifies the relationship between integral grid sizes for the window and pixel sizes. to return to non-gridded geometry management, invoke grid with empty argument strings β empty strings are the exit door πͺ.
when gridded geometry management is enabled then all the dimensions specified in minsize, maxsize, and geometry methods are treated as grid units rather than pixel units. interactive resizing is also carried out in even numbers of grid units rather than pixels. snap snap snap π₯.
π BUGS π
most existing window managers appear to have bugs that affect the operation of the wm methods. for example, some changes won't take effect if the window is already active: the window will have to be withdrawn and de-iconified in order to make the change happen. classic π.
π«Ά SEE ALSO π«Ά
Tk::Widget Tk::tixWm Tk::Mwm
π KEYWORDS π
aspect ratio, deiconify, focus model, geometry, grid, group, icon, iconify, increments, position, size, title, top-level window, units, window manager
and that's the whole thing bestie, you ate that whole page πβ¨ this one ships as part of perl v5.40.1, dated 2025-04-13 β go be a window-managing icon ππ
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms