i3
Main Page
Data Structures
Files
File List
Globals
src
scratchpad.c
Go to the documentation of this file.
1
/*
2
* vim:ts=4:sw=4:expandtab
3
*
4
* i3 - an improved dynamic tiling window manager
5
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
6
*
7
* scratchpad.c: Moving windows to the scratchpad and making them visible again.
8
*
9
*/
10
#include "
all.h
"
11
12
/*
13
* Moves the specified window to the __i3_scratch workspace, making it floating
14
* and setting the appropriate scratchpad_state.
15
*
16
* Gets called upon the command 'move scratchpad'.
17
*
18
*/
19
void
scratchpad_move
(
Con
*con) {
20
if
(con->
type
== CT_WORKSPACE) {
21
LOG
(
"'move scratchpad' used on a workspace \"%s\". Calling it "
22
"recursively on all windows on this workspace.\n"
, con->
name
);
23
Con
*current;
24
current =
TAILQ_FIRST
(&(con->focus_head));
25
while
(current) {
26
Con
*next =
TAILQ_NEXT
(current,
focused
);
27
scratchpad_move
(current);
28
current = next;
29
}
30
return
;
31
}
32
DLOG
(
"should move con %p to __i3_scratch\n"
, con);
33
34
Con
*__i3_scratch =
workspace_get
(
"__i3_scratch"
, NULL);
35
if
(
con_get_workspace
(con) == __i3_scratch) {
36
DLOG
(
"This window is already on __i3_scratch.\n"
);
37
return
;
38
}
39
40
/* 1: Ensure the window is floating. From now on, we deal with the
41
* CT_FLOATING_CON. We use automatic == false because the user made the
42
* choice that this window should be a scratchpad (and floating). */
43
floating_enable
(con,
false
);
44
con = con->
parent
;
45
46
/* 2: Send the window to the __i3_scratch workspace, mainting its
47
* coordinates and not warping the pointer. */
48
Con
*focus_next =
con_next_focused
(con);
49
con_move_to_workspace
(con, __i3_scratch,
true
,
true
);
50
51
/* 3: If this is the first time this window is used as a scratchpad, we set
52
* the scratchpad_state to SCRATCHPAD_FRESH. The window will then be
53
* adjusted in size according to what the user specifies. */
54
if
(con->
scratchpad_state
== SCRATCHPAD_NONE) {
55
DLOG
(
"This window was never used as a scratchpad before.\n"
);
56
con->
scratchpad_state
= SCRATCHPAD_FRESH;
57
}
58
59
/* 4: Fix focus. Normally, when moving a window to a different output, the
60
* destination output gets focused. In this case, we don’t want that. */
61
con_focus
(focus_next);
62
}
63
64
/*
65
* Either shows the top-most scratchpad window (con == NULL) or shows the
66
* specified con (if it is scratchpad window).
67
*
68
* When called with con == NULL and the currently focused window is a
69
* scratchpad window, this serves as a shortcut to hide it again (so the user
70
* can press the same key to quickly look something up).
71
*
72
*/
73
void
scratchpad_show
(
Con
*con) {
74
DLOG
(
"should show scratchpad window %p\n"
, con);
75
Con
*__i3_scratch =
workspace_get
(
"__i3_scratch"
, NULL);
76
Con
*floating;
77
78
/* If this was 'scratchpad show' without criteria, we check if the
79
* currently focused window is a scratchpad window and should be hidden
80
* again. */
81
if
(!con &&
82
(floating =
con_inside_floating
(
focused
)) &&
83
floating->
scratchpad_state
!= SCRATCHPAD_NONE) {
84
DLOG
(
"Focused window is a scratchpad window, hiding it.\n"
);
85
scratchpad_move
(
focused
);
86
return
;
87
}
88
89
/* If this was 'scratchpad show' with criteria, we check if it matches a
90
* currently visible scratchpad window and hide it. */
91
Con
*active =
con_get_workspace
(
focused
);
92
Con
*current =
con_get_workspace
(con);
93
if
(con &&
94
(floating =
con_inside_floating
(con)) &&
95
floating->
scratchpad_state
!= SCRATCHPAD_NONE &&
96
current != __i3_scratch) {
97
/* If scratchpad window is on the active workspace, then we should hide
98
* it, otherwise we should move it to the active workspace. */
99
if
(current == active) {
100
DLOG
(
"Window is a scratchpad window, hiding it.\n"
);
101
scratchpad_move
(con);
102
return
;
103
}
104
}
105
106
if
(con == NULL) {
107
/* Use the container on __i3_scratch which is highest in the focus
108
* stack. When moving windows to __i3_scratch, they get inserted at the
109
* bottom of the stack. */
110
con =
TAILQ_FIRST
(&(__i3_scratch->floating_head));
111
112
if
(!con) {
113
LOG
(
"You don't have any scratchpad windows yet.\n"
);
114
LOG
(
"Use 'move scratchpad' to move a window to the scratchpad.\n"
);
115
return
;
116
}
117
}
118
119
/* 1: Move the window from __i3_scratch to the current workspace. */
120
con_move_to_workspace
(con, active,
true
,
false
);
121
122
/* 2: Adjust the size if this window was not adjusted yet. */
123
if
(con->
scratchpad_state
== SCRATCHPAD_FRESH) {
124
DLOG
(
"Adjusting size of this window.\n"
);
125
Con
*
output
=
con_get_output
(con);
126
con->
rect
.
width
= output->
rect
.
width
* 0.5;
127
con->
rect
.
height
= output->
rect
.
height
* 0.75;
128
con->
rect
.
x
= output->
rect
.
x
+
129
((output->
rect
.
width
/ 2.0) - (con->
rect
.
width
/ 2.0));
130
con->
rect
.
y
= output->
rect
.
y
+
131
((output->
rect
.
height
/ 2.0) - (con->
rect
.
height
/ 2.0));
132
con->
scratchpad_state
= SCRATCHPAD_CHANGED;
133
}
134
135
/* Activate active workspace if window is from another workspace to ensure
136
* proper focus. */
137
if
(current != active) {
138
workspace_show
(active);
139
}
140
141
con_focus
(
con_descend_focused
(con));
142
}
Generated by
1.8.1.1