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/>.
32 int workspace_new(Workspace **out, Manager *m) {
33 _cleanup_(workspace_unrefp) Workspace *w = NULL;
38 w = new0(Workspace, 1);
44 LIST_PREPEND(workspaces_by_manager, m->workspace_list, w);
46 r = terminal_new(&w->current, w);
55 static void workspace_cleanup(Workspace *w) {
61 assert(!w->session_list);
64 while ((t = w->terminal_list))
67 LIST_REMOVE(workspaces_by_manager, w->manager->workspace_list, w);
71 Workspace *workspace_ref(Workspace *w) {
78 Workspace *workspace_unref(Workspace *w) {
90 Workspace *workspace_attach(Workspace *w, Session *s) {
94 LIST_PREPEND(sessions_by_workspace, w->session_list, s);
96 return workspace_ref(w);
99 Workspace *workspace_detach(Workspace *w, Session *s) {
102 assert(s->active_ws == w);
104 LIST_REMOVE(sessions_by_workspace, w->session_list, s);
105 workspace_refresh(w);
106 return workspace_unref(w);
109 void workspace_refresh(Workspace *w) {
110 uint32_t width, height;
120 /* find out minimum dimension of all attached displays */
121 LIST_FOREACH(sessions_by_workspace, s, w->session_list) {
122 LIST_FOREACH(displays_by_session, d, s->display_list) {
123 assert(d->width > 0 && d->height > 0);
125 if (width == 0 || d->width < width)
127 if (height == 0 || d->height < height)
132 /* either both are zero, or none is zero */
133 assert(!(!width ^ !height));
135 /* update terminal-sizes if dimensions changed */
136 if (w->width != width || w->height != height) {
140 LIST_FOREACH(terminals_by_workspace, t, w->terminal_list)
147 void workspace_dirty(Workspace *w) {
152 LIST_FOREACH(sessions_by_workspace, s, w->session_list)
156 void workspace_feed(Workspace *w, idev_data *data) {
160 terminal_feed(w->current, data);
163 bool workspace_draw(Workspace *w, const grdev_display_target *target) {
167 return terminal_draw(w->current, target);