1 | /* |
---|
2 | * neercs console-based window manager |
---|
3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
---|
4 | * 2008 Jean-Yves Lamoureux <jylam@lnxscene.org> |
---|
5 | * All Rights Reserved |
---|
6 | * |
---|
7 | * $Id: wm.c 2360 2008-06-11 16:23:46Z jylam $ |
---|
8 | * |
---|
9 | * This program is free software. It comes without any warranty, to |
---|
10 | * the extent permitted by applicable law. You can redistribute it |
---|
11 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
12 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
13 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
14 | */ |
---|
15 | |
---|
16 | #include <stdio.h> |
---|
17 | #include <cucul.h> |
---|
18 | #include <caca.h> |
---|
19 | #include <stdlib.h> |
---|
20 | |
---|
21 | #include "neercs.h" |
---|
22 | |
---|
23 | |
---|
24 | void resize_screen(struct screen *s, int w, int h) |
---|
25 | { |
---|
26 | cucul_canvas_t *old, *new; |
---|
27 | |
---|
28 | if(w==s->w && h==s->h) return; |
---|
29 | if(w <= 0 || h <= 0) return; |
---|
30 | |
---|
31 | s->w = w; |
---|
32 | s->h = h; |
---|
33 | |
---|
34 | /* cucul_set_canvas_boundaries() is bugged as hell, |
---|
35 | * so let's resize it by hands */ |
---|
36 | old = s->cv; |
---|
37 | new = cucul_create_canvas(w, h); |
---|
38 | cucul_blit(new, 0, 0, old, NULL); |
---|
39 | s->cv = new; |
---|
40 | cucul_free_canvas(old); |
---|
41 | set_tty_size(s->fd, w, h); |
---|
42 | |
---|
43 | s->orig_w = s->w; |
---|
44 | s->orig_h = s->h; |
---|
45 | s->orig_x = s->x; |
---|
46 | s->orig_y = s->y; |
---|
47 | } |
---|
48 | |
---|
49 | void update_windows_props(cucul_canvas_t *cv, struct screen_list *screen_list) |
---|
50 | { |
---|
51 | if(!screen_list->count) return; |
---|
52 | |
---|
53 | switch(screen_list->wm_type) |
---|
54 | { |
---|
55 | case WM_CARD: |
---|
56 | update_windows_props_cards(cv, screen_list); |
---|
57 | break; |
---|
58 | case WM_HSPLIT: |
---|
59 | update_windows_props_hsplit(cv, screen_list); |
---|
60 | break; |
---|
61 | case WM_VSPLIT: |
---|
62 | update_windows_props_vsplit(cv, screen_list); |
---|
63 | break; |
---|
64 | case WM_FULL: |
---|
65 | default: |
---|
66 | update_windows_props_full(cv, screen_list); |
---|
67 | break; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | void update_windows_props_hsplit(cucul_canvas_t *cv, struct screen_list *screen_list) |
---|
72 | { |
---|
73 | int i; |
---|
74 | int w = (screen_list->width / screen_list->count) - 1; |
---|
75 | int h = (screen_list->height) - 2; |
---|
76 | |
---|
77 | for(i = 0; i < screen_list->count; i++) |
---|
78 | { |
---|
79 | screen_list->screen[i]->x = (i*w)+1; |
---|
80 | screen_list->screen[i]->y = 1; |
---|
81 | screen_list->screen[i]->visible = 1; |
---|
82 | if(i != screen_list->count -1) |
---|
83 | { |
---|
84 | resize_screen(screen_list->screen[i], |
---|
85 | w - 1, h); |
---|
86 | } else { |
---|
87 | resize_screen(screen_list->screen[i], |
---|
88 | screen_list->width - i*w - 1, |
---|
89 | h); |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | void update_windows_props_vsplit(cucul_canvas_t *cv, struct screen_list *screen_list) |
---|
95 | { |
---|
96 | int i; |
---|
97 | int w = screen_list->width - 2; |
---|
98 | int h = (screen_list->height / screen_list->count); |
---|
99 | |
---|
100 | for(i = 0; i < screen_list->count; i++) |
---|
101 | { |
---|
102 | screen_list->screen[i]->x = 1; |
---|
103 | screen_list->screen[i]->y = (i*h) + 1; |
---|
104 | screen_list->screen[i]->visible = 1; |
---|
105 | if(i != screen_list->count -1) |
---|
106 | { |
---|
107 | resize_screen(screen_list->screen[i], |
---|
108 | w, h - 2); |
---|
109 | } else { |
---|
110 | resize_screen(screen_list->screen[i], |
---|
111 | w, |
---|
112 | screen_list->height - i*h - 2); |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | void update_windows_props_full(cucul_canvas_t *cv, struct screen_list *screen_list) |
---|
119 | { |
---|
120 | int i; |
---|
121 | int w = screen_list->width - 2; |
---|
122 | int h = screen_list->height - 2; |
---|
123 | |
---|
124 | for(i = 0; i < screen_list->count; i++) |
---|
125 | { |
---|
126 | screen_list->screen[i]->visible = 0; |
---|
127 | screen_list->screen[i]->x = 1; |
---|
128 | screen_list->screen[i]->y = 1; |
---|
129 | |
---|
130 | resize_screen(screen_list->screen[i], |
---|
131 | w, h); |
---|
132 | } |
---|
133 | screen_list->screen[screen_list->pty]->visible = 1; |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | void update_windows_props_cards(cucul_canvas_t *cv, struct screen_list *screen_list) |
---|
138 | { |
---|
139 | int i; |
---|
140 | int w = (screen_list->width - screen_list->count) - 3; |
---|
141 | int h = (screen_list->height - screen_list->count) - 4; |
---|
142 | int x = (screen_list->width - w) - (3*screen_list->count) + 4; |
---|
143 | int y = 2 + (1*screen_list->count); |
---|
144 | |
---|
145 | for(i = 0; i < screen_list->count; i++) |
---|
146 | { |
---|
147 | screen_list->screen[i]->visible = 1; |
---|
148 | screen_list->screen[i]->x = x; |
---|
149 | screen_list->screen[i]->y = y; |
---|
150 | |
---|
151 | resize_screen(screen_list->screen[i], |
---|
152 | w, h); |
---|
153 | x += 3; |
---|
154 | y--; |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|