summaryrefslogtreecommitdiff
path: root/src/bclient.c
blob: ba9caf4c125f12b352902ca21aa7666a7f791032 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
 * @file
 * @section AUTHORS
 *
 *  Authors:
 *       Eamon Walsh <ewalsh@tycho.nsa.gov>
 *
 * @section LICENSE
 *
 * This file is in the public domain.
 *
 * @section DESCRIPTION
 *
 * This is the "subclass" of display that implements a single view
 * consisting of the entirety of a buffer.  In other words, this is the
 * standard client display for doing a fullscreen framebuffer from a guest.
 * With the exception of the combined desktop and the server screen, all
 * of the display objects will be of this type.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sys-queue.h"
#include "xen_linpicker.h"
#include "client.h"
#include "view.h"
#include "display.h"
#include "input.h"

static int
bclient_key(struct display *d, bool down, int keycode)
{
    if (d->client->input)
	xenfb_send_key(d->client->input, down, keycode);

    return 0;
}

static int
bclient_position(struct display *d, int x, int y)
{
    struct view *v;
    struct client *c;

    TAILQ_FOREACH(v, &d->views, display_next)
	if (x >= v->spos.x && x < (v->spos.x + v->spos.w) &&
	    y >= v->spos.y && y < (v->spos.y + v->spos.h))
	    break;

    /* What client is the mouse over? */
    c = v ? v->buffer->client : NULL;

    /* Mouselabel update */
    if (c != d->mouse_client)
    {
	d->mouse_client = c;
	display_update_mouselabel(d, c);
    }

    return 0;
}

static int
bclient_mouse(struct display *d, struct mouse_event *m)
{
    struct buffer *b = LIST_FIRST(&d->buffers);

    /* Update position */
    bclient_position(d, m->x, m->y);

    /* Remove the buffer offset */
    /* Clamp the position to the buffer bounds */
    /* Scale the position to the dimensions the frontend expects */
    if (b->xoff > 0 || b->yoff > 0) {
	m->x = scale_value(m->x - b->xoff, b->desc.width, display_get_width());
	m->y = scale_value(m->y - b->yoff, b->desc.height, display_get_height());
    }

    if (d->client->input)
	xen_linpicker_input_send(d->client->input, m);
    return 0;
}

struct display *
bclient_new(struct buffer *b)
{
    struct display *d = calloc(1, sizeof(struct display));
    if (!d)
	return NULL;

    /* Set up input methods */
    d->send_key = bclient_key;
    d->send_mouse = bclient_mouse;
    d->update_position = bclient_position;

    d->type = DISPLAY_BUFFER;
    d->client = b->client;
    LIST_INIT(&d->buffers);
    LIST_INSERT_HEAD(&d->buffers, b, display_next);
    TAILQ_INIT(&d->views);
    d->bg_view = b->bg_view;

    return d;
}