File: ww-layout-twothirds.c

package info (click to toggle)
winwrangler 0.2.4-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, jessie, jessie-kfreebsd, stretch
  • size: 1,612 kB
  • ctags: 169
  • sloc: sh: 10,265; ansic: 935; makefile: 96
file content (105 lines) | stat: -rw-r--r-- 2,745 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
   -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- 
 */
/*
 * This file is part of WinWrangler.
 * Copyright (C) Alessio 'molok' Bolognino <themolok@gmail.com>
 *
 *	WinWrangler is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *	
 *	WinWrangler is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with WinWranger.	If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include "winwrangler.h"

/**
 * ww_layout_twothirds
 * @screen: The screen to work on
 * @windows: A list of all windows on the @screen
 * @active: The currently active window
 * @error: %GError to set on failure
 *
 * A %WwLayoutHandler resizing the active window to 2/3 of the screen
 */
void
ww_layout_twothirds (WnckScreen	*screen,
				GList		*windows,
				GList		*struts,
				WnckWindow	*active,
				GError		**error)
{
	GList	*next;
	int		dim, row;
	int		r_cell_w, r_cell_h;
	int		edge_l, edge_t, edge_b, edge_r;
	int		lg_h, lg_w, rg_h, rg_w;
	
	g_return_if_fail (WNCK_IS_SCREEN(screen));
	if (g_list_length(windows) == 0)
		return;
	
	ww_calc_bounds (screen, struts, &edge_l, &edge_t, &edge_r, &edge_b);
	
	lg_w = (edge_r - edge_l ) / 3 * 2;
	rg_w = (edge_r - edge_l) - lg_w;

	lg_h = rg_h = edge_b - edge_t;

	dim = g_list_length(windows);

	/* If there is only one window, resize it to fullscreen and exit */
	if ( dim == 1 ) {
		wnck_window_set_geometry (windows->data,
								  WNCK_WINDOW_GRAVITY_STATIC,
								  WW_MOVERESIZE_FLAGS, 
								  edge_l, edge_t,
								  edge_r - edge_l,
								  edge_b - edge_t);
		return;
	}

	dim -= 1;

	/* If there is no active window, do nothing */
	if (active == NULL
	    || wnck_window_is_skip_tasklist (active)) {
		g_debug ("No active window");
		return;
	}

	r_cell_w = rg_w;
	r_cell_h = rg_h / dim;

	row = 0;
	for (next = windows; next; next = next->next) 
	{
		if (wnck_window_is_active (next->data) == TRUE) 
		{
			wnck_window_set_geometry (next->data,
									  WNCK_WINDOW_GRAVITY_STATIC,
									  WW_MOVERESIZE_FLAGS, 
									  edge_l, edge_t , lg_w, lg_h);
		} else {
			wnck_window_set_geometry (next->data, 
									  WNCK_WINDOW_GRAVITY_STATIC,
									  WW_MOVERESIZE_FLAGS, 
									  lg_w + edge_l, row*r_cell_h + edge_t,
									  r_cell_w, r_cell_h);
			row++;
		}
	}
}