summaryrefslogtreecommitdiff
path: root/gwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'gwm.c')
-rw-r--r--gwm.c216
1 files changed, 6 insertions, 210 deletions
diff --git a/gwm.c b/gwm.c
index ef8761b..4d9cbf0 100644
--- a/gwm.c
+++ b/gwm.c
@@ -979,211 +979,6 @@ extern CONST int final_release( xcb_button_release_event_t *ev ) {
return ( ev->state & 0x1F00 ) == ( 0x80 << ev->detail );
}
-extern void translate_child_to_frame( int *fx, int *fy, int *fwidth,
- int *fheight, int cx, int cy,
- int cwidth, int cheight,
- int cborder, int win_gravity ) {
-
- *fwidth = cwidth + FRAME_BORDER_WIDTH * 2;
- *fheight = cheight + FRAME_BORDER_WIDTH + FRAME_TITLE_HEIGHT;
-
- switch( win_gravity ) {
- case XCB_GRAVITY_NORTH_WEST:
- case XCB_GRAVITY_WEST:
- case XCB_GRAVITY_SOUTH_WEST:
- default:
- *fx = cx;
- break;
-
- case XCB_GRAVITY_NORTH:
- case XCB_GRAVITY_CENTER:
- case XCB_GRAVITY_SOUTH:
- case XCB_GRAVITY_STATIC:
- *fx = cx + cborder - FRAME_BORDER_WIDTH - FRAME_X_BORDER;
- break;
-
- case XCB_GRAVITY_NORTH_EAST:
- case XCB_GRAVITY_EAST:
- case XCB_GRAVITY_SOUTH_EAST:
- *fx = cx + ( ( cborder - FRAME_BORDER_WIDTH - FRAME_X_BORDER ) << 1 );
- break;
- }
-
- switch( win_gravity ) {
- case XCB_GRAVITY_NORTH_WEST:
- case XCB_GRAVITY_NORTH:
- case XCB_GRAVITY_NORTH_EAST:
- default:
- *fy = cy;
- break;
-
- case XCB_GRAVITY_WEST:
- case XCB_GRAVITY_CENTER:
- case XCB_GRAVITY_EAST:
- *fy = cy + cborder - ( ( FRAME_BORDER_WIDTH +
- FRAME_TITLE_HEIGHT ) >> 1 ) - FRAME_X_BORDER;
- break;
-
- case XCB_GRAVITY_SOUTH_WEST:
- case XCB_GRAVITY_SOUTH:
- case XCB_GRAVITY_SOUTH_EAST:
- *fy = cy + ( cborder << 1 ) - FRAME_TITLE_HEIGHT - FRAME_BORDER_WIDTH -
- ( FRAME_X_BORDER << 1 );
- break;
-
- case XCB_GRAVITY_STATIC:
- *fy = cy + cborder - FRAME_TITLE_HEIGHT - FRAME_X_BORDER;
- break;
- }
-}
-
-extern void translate_frame_to_child( int *cx, int *cy, int fx, int fy,
- int cborder, int win_gravity ) {
-
- switch( win_gravity ) {
- case XCB_GRAVITY_NORTH_WEST:
- case XCB_GRAVITY_WEST:
- case XCB_GRAVITY_SOUTH_WEST:
- default:
- *cx = fx;
- break;
-
- case XCB_GRAVITY_NORTH:
- case XCB_GRAVITY_CENTER:
- case XCB_GRAVITY_SOUTH:
- case XCB_GRAVITY_STATIC:
- *cx = fx - cborder + FRAME_BORDER_WIDTH + FRAME_X_BORDER;
- break;
-
- case XCB_GRAVITY_NORTH_EAST:
- case XCB_GRAVITY_EAST:
- case XCB_GRAVITY_SOUTH_EAST:
- *cx = fx + ( ( FRAME_BORDER_WIDTH + FRAME_X_BORDER - cborder ) << 1 );
- break;
- }
-
- switch( win_gravity ) {
- case XCB_GRAVITY_NORTH_WEST:
- case XCB_GRAVITY_NORTH:
- case XCB_GRAVITY_NORTH_EAST:
- default:
- *cy = fy;
- break;
-
- case XCB_GRAVITY_WEST:
- case XCB_GRAVITY_CENTER:
- case XCB_GRAVITY_EAST:
- *cy = fy - cborder + ( ( FRAME_BORDER_WIDTH +
- FRAME_TITLE_HEIGHT ) >> 1 ) + FRAME_X_BORDER;
- break;
-
- case XCB_GRAVITY_SOUTH_WEST:
- case XCB_GRAVITY_SOUTH:
- case XCB_GRAVITY_SOUTH_EAST:
- *cy = fy - ( cborder << 1 ) + FRAME_TITLE_HEIGHT + FRAME_BORDER_WIDTH +
- ( FRAME_X_BORDER << 1 );
- break;
-
- case XCB_GRAVITY_STATIC:
- *cy = fy - cborder + FRAME_TITLE_HEIGHT + FRAME_X_BORDER;
- break;
- }
-}
-
-extern void apply_size_constraints( struct gwm_window *window, int *width,
- int *height ) {
-
- int eff_base_width = window->u.managed.base_width ?
- window->u.managed.base_width : window->u.managed.min_width,
- eff_base_height = window->u.managed.base_height ?
- window->u.managed.base_height : window->u.managed.min_height;
-
- /* Apply the minimum and maximum constraints. These are already known
- to be compatible. */
- if( *width < window->u.managed.min_width )
- *width = window->u.managed.min_width;
-
- if( *height < window->u.managed.min_height )
- *height = window->u.managed.min_height;
-
- if( *width > window->u.managed.max_width )
- *width = window->u.managed.max_width;
-
- if( *height > window->u.managed.max_height )
- *height = window->u.managed.max_height;
-
- /* Now round down each dimension to an integer multiple of increments.
- Rounding down cannot violate the maximum constraint, and since
- eff_base_* >= min_*, it will not reduce below the minimum constraint. */
- *width -= ( *width - eff_base_width ) % window->u.managed.width_inc;
- *height -= ( *height - eff_base_height ) % window->u.managed.height_inc;
-
- if( window->u.managed.min_aspect_x * *height >
- window->u.managed.min_aspect_y * *width ) {
- /* Minimum aspect ratio violated. Attempt to either increase the
- width or decrease the height (whichever is a smaller change), but
- don't do either if it would go outside the min/max bounds.
- Both division operations are safe (min_aspect_y is always
- positive, and min_aspect_x must be positive if there is a
- violation). Note that an exact solution might not be possible
- (e.g. certain cases where the aspect ratio and increments are
- coprime). */
- int min_x, max_y;
-
- min_x = ( window->u.managed.min_aspect_x * *height +
- ( window->u.managed.min_aspect_y - 1 ) ) /
- window->u.managed.min_aspect_y + window->u.managed.width_inc - 1;
- min_x -= ( min_x - eff_base_width ) % window->u.managed.width_inc;
-
- max_y = window->u.managed.min_aspect_y * *width /
- window->u.managed.min_aspect_x;
- max_y -= ( max_y - eff_base_height ) % window->u.managed.height_inc;
-
- if( min_x - *width < *height - max_y ) {
- /* The width change is smaller: prefer it if possible. */
- if( min_x >= window->u.managed.min_width )
- *width = min_x;
- else if( max_y < window->u.managed.max_height )
- *height = max_y;
- } else {
- /* The height change is smaller: prefer it if possible. */
- if( max_y < window->u.managed.max_height )
- *height = max_y;
- else if( min_x >= window->u.managed.min_width )
- *width = min_x;
- }
- }
-
- if( window->u.managed.max_aspect_x * *height <
- window->u.managed.max_aspect_y * *width ) {
- /* Maximum aspect ratio violated. Much like the case above... */
- int min_y, max_x;
-
- min_y = ( window->u.managed.max_aspect_y * *width +
- ( window->u.managed.max_aspect_x - 1 ) ) /
- window->u.managed.max_aspect_x + window->u.managed.height_inc - 1;
- min_y -= ( min_y - eff_base_height ) % window->u.managed.height_inc;
-
- max_x = window->u.managed.max_aspect_x * *height /
- window->u.managed.max_aspect_y;
- max_x -= ( max_x - eff_base_width ) % window->u.managed.width_inc;
-
- if( min_y - *height < *width - max_x ) {
- /* The height change is smaller: prefer it if possible. */
- if( min_y >= window->u.managed.min_height )
- *height = min_y;
- else if( max_x < window->u.managed.max_width )
- *width = max_x;
- } else {
- /* The width change is smaller: prefer it if possible. */
- if( max_x < window->u.managed.max_width )
- *width = max_x;
- else if( min_y >= window->u.managed.min_height )
- *height = min_y;
- }
- }
-}
-
static void stop_listening( struct gwm_window *window ) {
uint32_t value;
@@ -1279,7 +1074,7 @@ static void start_managing_window( struct gwm_window *window,
for( i = 0; i < NUM_PROPS; i++ )
managed_property_change( window, i, props[ i ] );
- translate_child_to_frame( &frame->u.frame.x, &frame->u.frame.y,
+ translate_child_to_frame( frame, &frame->u.frame.x, &frame->u.frame.y,
&frame->u.frame.width, &frame->u.frame.height,
geom->x, geom->y, geom->width, geom->height,
geom->border_width,
@@ -1339,7 +1134,8 @@ static void start_managing_window( struct gwm_window *window,
values[ 2 ] = TRUE; /* override redirect */
values[ 3 ] = XCB_EVENT_MASK_EXPOSURE;
xcb_create_window( c, XCB_COPY_FROM_PARENT, button->w, frame->w,
- 2, 1, FRAME_BUTTON_SIZE, FRAME_BUTTON_SIZE, 1,
+ 2, 1, button_size( button, FALSE ),
+ button_size( button, FALSE ), button_xb( button ),
XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT,
XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL |
XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK, values );
@@ -1365,8 +1161,8 @@ static void start_managing_window( struct gwm_window *window,
xcb_change_window_attributes( c, w, XCB_CW_EVENT_MASK, values );
}
- xcb_reparent_window( c, w, frame->w, FRAME_BORDER_WIDTH,
- FRAME_TITLE_HEIGHT );
+ xcb_reparent_window( c, w, frame->w, frame_l( frame, FALSE ),
+ frame_t( frame, FALSE ) );
if( !map_request ) {
values[ 0 ] = XCB_EVENT_MASK_STRUCTURE_NOTIFY |
XCB_EVENT_MASK_PROPERTY_CHANGE |
@@ -1576,7 +1372,7 @@ extern void unmanage_window( struct gwm_window *window ) {
/* Reparent the window back to the root; delete its WM_STATE
property (see ICCCM 4.1.4); and map it if it was iconic. */
- translate_frame_to_child( &x, &y, frame->u.frame.x, frame->u.frame.y,
+ translate_frame_to_child( frame, &x, &y, frame->u.frame.x, frame->u.frame.y,
border_width, window->u.managed.win_gravity );
handle_error_reply( xcb_reparent_window_checked(
c, w, screens[ window->screen ]->root,