1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
31 int workspace_new(Workspace **out, Manager *m) {
32 _cleanup_(workspace_unrefp) Workspace *w = NULL;
37 w = new0(Workspace, 1);
43 LIST_PREPEND(workspaces_by_manager, m->workspace_list, w);
45 r = terminal_new(&w->current, w);
54 static void workspace_cleanup(Workspace *w) {
60 assert(!w->session_list);
63 while ((t = w->terminal_list))
66 LIST_REMOVE(workspaces_by_manager, w->manager->workspace_list, w);
70 Workspace *workspace_ref(Workspace *w) {
77 Workspace *workspace_unref(Workspace *w) {
89 Workspace *workspace_attach(Workspace *w, Session *s) {
93 LIST_PREPEND(sessions_by_workspace, w->session_list, s);
95 return workspace_ref(w);
98 Workspace *workspace_detach(Workspace *w, Session *s) {
101 assert(s->active_ws == w);
103 LIST_REMOVE(sessions_by_workspace, w->session_list, s);
104 workspace_refresh(w);
105 return workspace_unref(w);
108 void workspace_refresh(Workspace *w) {
109 uint32_t width, height;
119 /* find out minimum dimension of all attached displays */
120 LIST_FOREACH(sessions_by_workspace, s, w->session_list) {
121 LIST_FOREACH(displays_by_session, d, s->display_list) {
122 assert(d->width > 0 && d->height > 0);
124 if (width == 0 || d->width < width)
126 if (height == 0 || d->height < height)
131 /* either both are zero, or none is zero */
132 assert(!(!width ^ !height));
134 /* update terminal-sizes if dimensions changed */
135 if (w->width != width || w->height != height) {
139 LIST_FOREACH(terminals_by_workspace, t, w->terminal_list)
146 void workspace_dirty(Workspace *w) {
151 LIST_FOREACH(sessions_by_workspace, s, w->session_list)
155 void workspace_feed(Workspace *w, idev_data *data) {
159 terminal_feed(w->current, data);
162 bool workspace_draw(Workspace *w, const grdev_display_target *target) {
166 return terminal_draw(w->current, target);