source: neercs/trunk/src/wm.c @ 2421

Last change on this file since 2421 was 2421, checked in by jylam, 6 years ago
  • Put pty and prevpty in screen_list structure
File size: 4.0 KB
Line 
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
24void 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
44void update_windows_props(cucul_canvas_t *cv, struct screen_list *screen_list)
45{
46    if(!screen_list->count) return;
47
48    switch(screen_list->wm_type)
49    {
50    case WM_CARD:
51        update_windows_props_cards(cv, screen_list);
52        break;
53    case WM_HSPLIT:
54        update_windows_props_hsplit(cv, screen_list);
55        break;
56    case WM_VSPLIT:
57        update_windows_props_vsplit(cv, screen_list);
58        break;
59    case WM_FULL:
60    default:
61        update_windows_props_full(cv, screen_list);
62        break;
63    }
64}
65
66void update_windows_props_hsplit(cucul_canvas_t *cv, struct screen_list *screen_list)
67{
68    int i;
69    int w = (screen_list->width / screen_list->count) - 1;
70    int h = (screen_list->height) - 2;
71
72    for(i = 0; i < screen_list->count; i++)
73    {
74        screen_list->screen[i]->x = (i*w)+1;
75        screen_list->screen[i]->y = 1;
76        screen_list->screen[i]->visible = 1;
77        if(i != screen_list->count -1)
78        {
79            resize_screen(screen_list->screen[i],
80                          w - 1, h);
81        } else {
82            resize_screen(screen_list->screen[i],
83                          screen_list->width - i*w - 1,
84                          h);
85        }
86    }
87}
88
89void update_windows_props_vsplit(cucul_canvas_t *cv, struct screen_list *screen_list)
90{
91    int i;
92    int w = screen_list->width - 2;
93    int h = (screen_list->height / screen_list->count);
94
95    for(i = 0; i < screen_list->count; i++)
96    {
97        screen_list->screen[i]->x = 1;
98        screen_list->screen[i]->y = (i*h) + 1;
99        screen_list->screen[i]->visible = 1;
100        if(i != screen_list->count -1)
101        {
102            resize_screen(screen_list->screen[i],
103                          w, h - 2);
104        } else {
105            resize_screen(screen_list->screen[i],
106                          w,
107                          screen_list->height - i*h - 2);
108        }
109    }
110}
111
112
113void update_windows_props_full(cucul_canvas_t *cv, struct screen_list *screen_list)
114{
115    int i;
116    int w = screen_list->width - 2;
117    int h = screen_list->height - 2;
118
119    for(i = 0; i < screen_list->count; i++)
120    {
121        screen_list->screen[i]->visible = 0;
122        screen_list->screen[i]->x = 1;
123        screen_list->screen[i]->y = 1;
124
125        resize_screen(screen_list->screen[i],
126                      w, h);
127    }
128    screen_list->screen[screen_list->pty]->visible = 1;
129}
130
131
132void update_windows_props_cards(cucul_canvas_t *cv, struct screen_list *screen_list)
133{
134    int i;
135    int w = (screen_list->width  - screen_list->count) - 3;
136    int h = (screen_list->height - screen_list->count) - 4;
137    int x = (screen_list->width  - w) - (3*screen_list->count) + 4;
138    int y = 2 + (1*screen_list->count);
139
140    for(i = 0; i < screen_list->count; i++)
141    {
142        screen_list->screen[i]->visible = 1;
143        screen_list->screen[i]->x = x;
144        screen_list->screen[i]->y = y;
145
146        resize_screen(screen_list->screen[i],
147                      w, h);
148        x += 3;
149        y--;
150    }
151}
152
Note: See TracBrowser for help on using the repository browser.