CTWM
|
#include "ctwm.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "r_layout.h"
#include "r_area_list.h"
#include "r_area.h"
#include "util.h"
Go to the source code of this file.
Data Structures | |
struct | monitor_finder_xy |
Internal structure for callback in RLayoutGetAreaAtXY(). More... | |
struct | monitor_edge_finder |
Internal struct for use in FindMonitor*Edge() callbacks. More... | |
Functions | |
static void | _RLayoutFreeNames (RLayout *self) |
Clean up and free any RLayout.names there might be in an RLayout. | |
static RAreaList * | _RLayoutRecenterVertically (const RLayout *self, const RArea *far_area) |
Given an RArea that doesn't reside in any of the areas in our RLayout, create a list of maximally-tall RArea slices out of our layout where it would wind up if we brought it onto the nearest screen edge. | |
static RAreaList * | _RLayoutRecenterHorizontally (const RLayout *self, const RArea *far_area) |
Given an RArea that doesn't reside in any of the areas in our RLayout, create a list of maximally-wide RArea slices out of our layout where it would wind up if we brought it onto the nearest screen edge. | |
static RAreaList * | _RLayoutVerticalIntersect (const RLayout *self, const RArea *area) |
Find which vertical regions of our monitor layout a given RArea (often a window) is in. | |
static RAreaList * | _RLayoutHorizontalIntersect (const RLayout *self, const RArea *area) |
Find which horizontal regions of our monitor layout a given RArea (often a window) is in. | |
static bool | _findMonitorByXY (const RArea *cur, void *vdata) |
Callback util for RLayoutGetAreaAtXY(). | |
static bool | _findMonitorBottomEdge (const RArea *cur, void *vdata) |
Callback util for RLayoutFindMonitorBottomEdge() | |
static bool | _findMonitorTopEdge (const RArea *cur, void *vdata) |
Callback util for RLayoutFindMonitorTopEdge() | |
static bool | _findMonitorLeftEdge (const RArea *cur, void *vdata) |
Callback util for RLayoutFindMonitorLeftEdge() | |
static bool | _findMonitorRightEdge (const RArea *cur, void *vdata) |
Callback util for RLayoutFindMonitorRightEdge() | |
RLayout * | RLayoutNew (RAreaList *monitors) |
Create an RLayout for a given set of monitors. | |
RLayout * | RLayoutCopyCropped (const RLayout *self, int left_margin, int right_margin, int top_margin, int bottom_margin) |
Create a copy of an RLayout with given amounts cropped off the sides. | |
void | RLayoutFree (RLayout *self) |
Clean up and free an RLayout. | |
RLayout * | RLayoutSetMonitorsNames (RLayout *self, char **names) |
Set the names for our monitors in an RLayout. | |
void | RLayoutFindTopBottomEdges (const RLayout *self, const RArea *area, int *top, int *bottom) |
Figure the position (or nearest practical position) of an area in our screen layout, and return info about the bottom/top stripes it fits into. | |
int | RLayoutFindBottomEdge (const RLayout *self, const RArea *area) |
Find the bottom of the top stripe of self that area fits into. | |
int | RLayoutFindTopEdge (const RLayout *self, const RArea *area) |
Find the top of the bottom stripe of self that area fits into. | |
void | RLayoutFindLeftRightEdges (const RLayout *self, const RArea *area, int *left, int *right) |
Figure the position (or nearest practical position) of an area in our screen layout, and return info about the left/rightmost stripes it fits into. | |
int | RLayoutFindLeftEdge (const RLayout *self, const RArea *area) |
Find the left edge of the right-most stripe of self that area fits into. | |
int | RLayoutFindRightEdge (const RLayout *self, const RArea *area) |
Find the right edge of the left-most stripe of self that area fits into. | |
RArea | RLayoutGetAreaAtXY (const RLayout *self, int x, int y) |
Find the RArea in a RLayout that a given coordinate falls into. | |
RArea | RLayoutGetAreaIndex (const RLayout *self, int index) |
Return the index'th RArea in an RLayout, or RAreaInvalid() with an out of range index. | |
RArea | RLayoutGetAreaByName (const RLayout *self, const char *name, int len) |
Return the RArea in self with the name given by the string of length len at name. | |
int | RLayoutFindMonitorBottomEdge (const RLayout *self, const RArea *area) |
Find the bottom edge of the top-most monitor that contains the most of a given RArea. | |
int | RLayoutFindMonitorTopEdge (const RLayout *self, const RArea *area) |
Find the top edge of the bottom-most monitor that contains the most of a given RArea. | |
int | RLayoutFindMonitorLeftEdge (const RLayout *self, const RArea *area) |
Find the left edge of the right-most monitor that contains the most of a given RArea. | |
int | RLayoutFindMonitorRightEdge (const RLayout *self, const RArea *area) |
Find the right edge of the left-most monitor that contains the most of a given RArea. | |
RArea | RLayoutFullHoriz (const RLayout *self, const RArea *area) |
Figure the best way to stretch an area across the full horizontal width of an RLayout. | |
RArea | RLayoutFullVert (const RLayout *self, const RArea *area) |
Figure the best way to stretch an area across the full vertical height of an RLayout. | |
RArea | RLayoutFull (const RLayout *self, const RArea *area) |
Figure the best way to stretch an area across the largest horizontal and vertical space it can from its current position. | |
RArea | RLayoutFullHoriz1 (const RLayout *self, const RArea *area) |
Figure the best way to stretch an area horizontally without crossing monitors. | |
RArea | RLayoutFullVert1 (const RLayout *self, const RArea *area) |
Figure the best way to stretch an area vertically without crossing monitors. | |
RArea | RLayoutFull1 (const RLayout *self, const RArea *area) |
Figure the best way to resize an area to fill one monitor. | |
RArea | RLayoutBigArea (const RLayout *self) |
Generate maximal spanning RArea. | |
int | RLayoutNumMonitors (const RLayout *self) |
How many monitors does a given RLayout contain? | |
void | RLayoutPrint (const RLayout *self) |
Pretty-print an RLayout. | |
Callback util for RLayoutFindMonitorBottomEdge()
Definition at line 618 of file r_layout.c.
References monitor_edge_finder::min_y2, PlaceX, RAreaIsIntersect(), RAreaY2(), and monitor_edge_finder::u.
Referenced by RLayoutFindMonitorBottomEdge().
Callback util for RLayoutGetAreaAtXY().
Definition at line 527 of file r_layout.c.
References monitor_finder_xy::area, PlaceX, and RAreaContainsXY().
Referenced by RLayoutGetAreaAtXY().
Callback util for RLayoutFindMonitorLeftEdge()
Definition at line 696 of file r_layout.c.
References monitor_edge_finder::max_x, PlaceX, RAreaIsIntersect(), and monitor_edge_finder::u.
Referenced by RLayoutFindMonitorLeftEdge().
Callback util for RLayoutFindMonitorRightEdge()
Definition at line 736 of file r_layout.c.
References monitor_edge_finder::min_x2, PlaceX, RAreaIsIntersect(), RAreaX2(), and monitor_edge_finder::u.
Referenced by RLayoutFindMonitorRightEdge().
Callback util for RLayoutFindMonitorTopEdge()
Definition at line 657 of file r_layout.c.
References monitor_edge_finder::max_y, PlaceX, RAreaIsIntersect(), and monitor_edge_finder::u.
Referenced by RLayoutFindMonitorTopEdge().
Clean up and free any RLayout.names there might be in an RLayout.
Definition at line 96 of file r_layout.c.
References PlaceX.
Referenced by RLayoutFree(), and RLayoutSetMonitorsNames().
Find which horizontal regions of our monitor layout a given RArea (often a window) is in.
If it's completely off the screen, we move it until it's just over the nearest edge, and return the horizontal stripe(s) it would be in then.
This function is used only by RLayoutFindLeftRightEdges()
Definition at line 357 of file r_layout.c.
References _RLayoutRecenterHorizontally(), PlaceX, RAreaListFree(), and RAreaListIntersect().
Referenced by RLayoutFindLeftRightEdges().
|
static |
Given an RArea that doesn't reside in any of the areas in our RLayout, create a list of maximally-wide RArea slices out of our layout where it would wind up if we brought it onto the nearest screen edge.
This yields a RAreaList as wide as the slice[es] the window would touch if we moved it in.
If we had the move the window vertically (it was off-screen to the top or bottom), it results in a 1-pixel-wide slice of the top- or bottom-most self->horiz.
If we had to move it horizontally (it was off to the left or right), it winds up being whatever vertical intersection with self->horiz would result from the window's y and height, with the full width of the involved slices.
This is the horizontal-stripe-returning counterpart of _RLayoutRecenterVertically().
This is called only by _RLayoutVerticalIntersect() when given an RArea that doesn't already intersect the RLayout. Will probably not tell you something useful if given a far_area that already does intersect self.
self | Our current monitor layout |
far_area | The area to act on |
Definition at line 263 of file r_layout.c.
References PlaceX, RAreaListBigArea(), RAreaListIntersect(), RAreaNew(), and RAreaY2().
Referenced by _RLayoutHorizontalIntersect(), and RLayoutFull1().
|
static |
Given an RArea that doesn't reside in any of the areas in our RLayout, create a list of maximally-tall RArea slices out of our layout where it would wind up if we brought it onto the nearest screen edge.
This yields a RAreaList as tall as the slice[es] the window would touch if we moved it in.
If we had the move the window horizontally (it was off-screen to the right or left), it results in a 1-pixel-wide slice of the right- or left-most self->vert.
If we had to move it vertically (it was off to the top or bottom), it winds up being whatever horizontal intersection with self->vert would result from the window's x and width, with the full height of the involved slices.
This is the vertical-stripe-returning counterpart of _RLayoutRecenterHorizontally().
This is called only by _RLayoutVerticalIntersect() when given an RArea that doesn't already intersect the RLayout. Will probably not tell you something useful if given a far_area that already does intersect self.
self | Our current monitor layout |
far_area | The area to act on |
Definition at line 178 of file r_layout.c.
References PlaceX, RAreaListBigArea(), RAreaListIntersect(), RAreaNew(), and RAreaX2().
Referenced by _RLayoutVerticalIntersect().
Find which vertical regions of our monitor layout a given RArea (often a window) is in.
If it's completely off the screen, we move it until it's just over the nearest edge, and return the vertical stripe(s) it would be in then.
This function is used only by RLayoutFindTopBottomEdges()
Definition at line 334 of file r_layout.c.
References _RLayoutRecenterVertically(), PlaceX, RAreaListFree(), and RAreaListIntersect().
Referenced by RLayoutFindTopBottomEdges().
Generate maximal spanning RArea.
This is a trivial wrapper of RAreaListBigArea() to hide knowledge of RLayout internals. Currently only used once; maybe should just be deref'd there...
Definition at line 1010 of file r_layout.c.
References PlaceX, and RAreaListBigArea().
Referenced by RLayoutXParseGeometry().
RLayout * RLayoutCopyCropped | ( | const RLayout * | self, |
int | left_margin, | ||
int | right_margin, | ||
int | top_margin, | ||
int | bottom_margin ) |
Create a copy of an RLayout with given amounts cropped off the sides.
This is used anywhere we need to pretend our display area is smaller than it actually is (e.g., via the BorderBottom/Top/Left/Right config params)
Definition at line 78 of file r_layout.c.
References PlaceX, RAreaListCopyCropped(), and RLayoutNew().
Referenced by ctwm_main(), and EwmhRecalculateStrut().
Find the bottom of the top stripe of self that area fits into.
A shortcut to get only the second return value of RLayoutFindTopBottomEdges().
Definition at line 424 of file r_layout.c.
References PlaceX, and RLayoutFindTopBottomEdges().
Referenced by ConstrainByLayout(), fullzoom(), RLayoutFindMonitorBottomEdge(), and SetupFrame().
Find the left edge of the right-most stripe of self that area fits into.
A shortcut to get only the first return value of RLayoutFindLeftRightEdges().
Definition at line 489 of file r_layout.c.
References PlaceX, and RLayoutFindLeftRightEdges().
Referenced by ConstrainByLayout(), fullzoom(), RLayoutFindMonitorLeftEdge(), and SetupFrame().
void RLayoutFindLeftRightEdges | ( | const RLayout * | self, |
const RArea * | area, | ||
int * | left, | ||
int * | right ) |
Figure the position (or nearest practical position) of an area in our screen layout, and return info about the left/rightmost stripes it fits into.
As with RLayoutFindTopBottomEdges(), the return values (params) are slightly counterintuitive. left tells you where the left-side of the right-most stripe that area intersects with is, and right tells you the right side of the left-most.
This is used as a backend piece of various calculations trying to be sure something winds up on-screen and when figuring out how to zoom it.
[in] | self | The monitor layout to work from |
[in] | area | The area to be fit into the monitors |
[out] | left | The left edge of the right-most stripe area fits into. |
[out] | right | The right edge of the left-most stripe area fits into. |
Definition at line 466 of file r_layout.c.
References _RLayoutHorizontalIntersect(), PlaceX, RAreaListFree(), RAreaListMaxX(), and RAreaListMinX2().
Referenced by AddWindow(), Identify(), RLayoutFindLeftEdge(), RLayoutFindRightEdge(), and RLayoutFullHoriz().
Find the bottom edge of the top-most monitor that contains the most of a given RArea.
Generally, the area would be a window.
That is, we find the monitor whose bottom is the highest up, but that still shows the bottom edge of the window, and return that monitor's bottom. If the bottom of the window is off all the monitors, that's just the highest-ending monitor that contains the window.
Definition at line 645 of file r_layout.c.
References _findMonitorBottomEdge(), monitor_edge_finder::area, PlaceX, RAreaListForeach(), and RLayoutFindBottomEdge().
Referenced by AddWindow(), FindConstraint(), and fullzoom().
Find the left edge of the right-most monitor that contains the most of a given RArea.
Generally, the area would be a window.
That is, we find the monitor whose left is the furthest right, but that still shows the left edge of the window, and return that monitor's left. If the left edge of the window is off all the monitors, that's just the right-most-ending monitor that contains the window.
Definition at line 724 of file r_layout.c.
References _findMonitorLeftEdge(), monitor_edge_finder::area, PlaceX, RAreaListForeach(), and RLayoutFindLeftEdge().
Referenced by FindConstraint(), and fullzoom().
Find the right edge of the left-most monitor that contains the most of a given RArea.
Generally, the area would be a window.
That is, we find the monitor whose right is the furthest left, but that still shows the right edge of the window, and return that monitor's right. If the right edge of the window is off all the monitors, that's just the left-most-ending monitor that contains the window.
Definition at line 764 of file r_layout.c.
References _findMonitorRightEdge(), monitor_edge_finder::area, PlaceX, RAreaListForeach(), and RLayoutFindRightEdge().
Referenced by AddWindow(), FindConstraint(), and fullzoom().
Find the top edge of the bottom-most monitor that contains the most of a given RArea.
Generally, the area would be a window.
That is, we find the monitor whose top is the lowest down, but that still shows the top edge of the window, and return that monitor's top. If the top of the window is off all the monitors, that's just the lowest-ending monitor that contains part of the window.
Definition at line 684 of file r_layout.c.
References _findMonitorTopEdge(), monitor_edge_finder::area, PlaceX, RAreaListForeach(), and RLayoutFindTopEdge().
Referenced by FindConstraint(), and fullzoom().
Find the right edge of the left-most stripe of self that area fits into.
A shortcut to get only the second return value of RLayoutFindLeftRightEdges().
Definition at line 503 of file r_layout.c.
References PlaceX, and RLayoutFindLeftRightEdges().
Referenced by ConstrainByLayout(), fullzoom(), RLayoutFindMonitorRightEdge(), and SetupFrame().
void RLayoutFindTopBottomEdges | ( | const RLayout * | self, |
const RArea * | area, | ||
int * | top, | ||
int * | bottom ) |
Figure the position (or nearest practical position) of an area in our screen layout, and return info about the bottom/top stripes it fits into.
Note that the return values (params) are slightly counterintuitive; top tells you where the top of the lowest stripe that area intersects with is, and bottom tells you the bottom of the highest.
This is used as a backend piece of various calculations trying to be sure something winds up on-screen and when figuring out how to zoom it.
[in] | self | The monitor layout to work from |
[in] | area | The area to be fit into the monitors |
[out] | top | The top of the lowest stripe area fits into. |
[out] | bottom | The bottom of the highest stripe area fits into. |
Definition at line 401 of file r_layout.c.
References _RLayoutVerticalIntersect(), PlaceX, RAreaListFree(), RAreaListMaxY(), and RAreaListMinY2().
Referenced by AddWindow(), Identify(), RLayoutFindBottomEdge(), RLayoutFindTopEdge(), and RLayoutFullVert().
Find the top of the bottom stripe of self that area fits into.
A shortcut to get only the first return value of RLayoutFindTopBottomEdges().
Definition at line 438 of file r_layout.c.
References PlaceX, and RLayoutFindTopBottomEdges().
Referenced by ConstrainByLayout(), fullzoom(), RLayoutFindMonitorTopEdge(), and SetupFrame().
Clean up and free an RLayout.
Definition at line 112 of file r_layout.c.
References _RLayoutFreeNames(), PlaceX, and RAreaListFree().
Referenced by fullzoom(), and proc_layout_override().
Figure the best way to stretch an area across the largest horizontal and vertical space it can from its current position.
Essentially, stretch it in all directions until it hits the edge of our available space.
This is the backend for the f.xfullzoom function.
Definition at line 883 of file r_layout.c.
References monitor_edge_finder::area, PlaceX, RAreaArea(), RLayoutFullHoriz(), and RLayoutFullVert().
Referenced by fullzoom().
Figure the best way to resize an area to fill one monitor.
This is the backend for the f.fullzoom ctwm function.
self | Monitor layout |
area | Area (window) to zoom out |
Definition at line 973 of file r_layout.c.
References _RLayoutRecenterHorizontally(), monitor_edge_finder::area, PlaceX, RAreaListBestTarget(), RAreaListFree(), and RAreaListIntersect().
Referenced by fullzoom(), RLayoutFullHoriz1(), and RLayoutFullVert1().
Figure the best way to stretch an area across the full horizontal width of an RLayout.
This is the backend for the f.xhorizoom ctwm function, zooming a window to the full width of all monitors.
This yields an area:
The precise construction of the area can be tricky.
In the simplest case, the area is entirely in one horizontal stripe to start with. In that case, max_x is the left side of that box, min_x2 is the right side, so the resulting area starts at (left margin, area y), with the height of y and the width of the whole stripe. Easy.
When it spans multiple, it's more convoluted. Let's consider an example layout (of horizontal stripes, so that top stripe may be across 2 monitors) to make it a little clearer:
So in this case, we're trying to stretch area out as far horizontal as it can go, crossing monitors if possible.
So, the top-left corner of our box (TL) has the X coordinate of the right-most strip we started with (the lower), and the Y coordinate of the top of the area, yielding point (1) above (not the asterisk; specifically where (1) sits).
The width W is the difference between the right of the left-most-ending (in this case, the top) stripe, and the left of the right-most-starting (the bottom) (plus 1 because math). That's the width of the intersecting horizontal area (2) above.
And the height H is just the height of the original area. And so, our resulting area is the height of that original area (in ='s), and stretched to the left and right until it runs into one or the other monitor edge (1 space to the left, 2 to the right, in our diagram).
Definition at line 789 of file r_layout.c.
References monitor_edge_finder::area, RArea::height, monitor_edge_finder::max_x, monitor_edge_finder::min_x2, PlaceX, RAreaNew(), RLayoutFindLeftRightEdges(), and RArea::y.
Referenced by fullzoom(), and RLayoutFull().
Figure the best way to stretch an area horizontally without crossing monitors.
This is the backend for the f.horizoom ctwm function.
Definition at line 909 of file r_layout.c.
References monitor_edge_finder::area, max(), monitor_edge_finder::max_y, min(), monitor_edge_finder::min_y2, PlaceX, RAreaY2(), RLayoutFull1(), and RArea::y.
Referenced by fullzoom().
Figure the best way to stretch an area across the full vertical height of an RLayout.
This is the backend for the f.xzoom ctwm function, zooming a window to the full height of all monitors.
Definition at line 860 of file r_layout.c.
References monitor_edge_finder::area, monitor_edge_finder::max_y, monitor_edge_finder::min_y2, PlaceX, RAreaNew(), RLayoutFindTopBottomEdges(), RArea::width, and RArea::x.
Referenced by fullzoom(), and RLayoutFull().
Figure the best way to stretch an area vertically without crossing monitors.
This is the backend for the f.zoom ctwm function.
Definition at line 942 of file r_layout.c.
References monitor_edge_finder::area, max(), monitor_edge_finder::max_x, min(), monitor_edge_finder::min_x2, PlaceX, RAreaX2(), RLayoutFull1(), and RArea::x.
Referenced by fullzoom().
Find the RArea in a RLayout that a given coordinate falls into.
In practice, the RArea's in self are the monitors of the desktop, so this answers "Which monitor is this position on?"
Definition at line 544 of file r_layout.c.
References _findMonitorByXY(), monitor_finder_xy::area, PlaceX, RAreaListForeach(), x, RArea::x, and y.
Referenced by MoveResizeSizeWindow().
Return the RArea in self with the name given by the string of length len at name.
This is only used in RLayoutXParseGeometry() to parse a fragment of a larger string, hence the need for len. It's used to find the monitor with a given name (RANDR output name).
Definition at line 576 of file r_layout.c.
References len, PlaceX, and RAreaInvalid().
Referenced by RLayoutXParseGeometry().
Return the index'th RArea in an RLayout, or RAreaInvalid() with an out of range index.
Definition at line 559 of file r_layout.c.
References PlaceX, and RAreaInvalid().
Referenced by ctwm_main().
Create an RLayout for a given set of monitors.
This stashes up the list of monitors, and precalculates the horizontal/vertical stripes that compose it.
Definition at line 55 of file r_layout.c.
References PlaceX, RAreaListHorizontalUnion(), and RAreaListVerticalUnion().
Referenced by ctwm_main(), fullzoom(), proc_layout_override(), RLayoutCopyCropped(), and XrandrNewLayout().
How many monitors does a given RLayout contain?
Definition at line 1020 of file r_layout.c.
References PlaceX.
Referenced by ctwm_main().
Pretty-print an RLayout.
Used for dev/debug.
Definition at line 1032 of file r_layout.c.
References PlaceX, and RAreaListPrint().
Referenced by ctwm_main(), and proc_layout_override().
Set the names for our monitors in an RLayout.
This is only used for the RLayout that describes our complete monitor layout, which fills in the RANDR names for each output.
Definition at line 132 of file r_layout.c.
References _RLayoutFreeNames(), names, and PlaceX.
Referenced by proc_layout_override(), and XrandrNewLayout().