summaryrefslogtreecommitdiff
path: root/src/qa-plugin/qa-plugin.c
blob: dc095d46185e368533edd488133b892baaf43430 (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
 /* Copyright 2014 Manuel Bachmann <tarnyko@tarnyko.net> */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server.h>

#include <weston/compositor.h>
#include "qa-server-protocol.h"

struct weston_compositor *ec = NULL;



static void
qa_surface_list (struct wl_client *client,
		 struct wl_resource *resource)
{
	struct weston_view *view;
	char *resp, *temp;

	weston_log ("qa-plugin: requested surfaces list...\n");

	resp = strdup ("");

	wl_list_for_each (view, &ec->view_list, link) { printf ("RHA ");
		if ((view->surface) &&
		    (view->geometry.x != 0.0) &&
		    (view->geometry.y != 0.0)) {
			asprintf (&temp, "Surface %p : X+Y = %.2f+%.2f - WxH = %dx%d\n",
				  view->surface, view->geometry.x, view->geometry.y,
				  view->surface->width, view->surface->height);
			resp = realloc (resp, strlen(resp) + strlen (temp) + 1);
			strncat (resp, temp, strlen(temp));
			free (temp);
		}
	}

	qa_send_list_surface (resource, resp);
	free (resp);
}

static void
qa_destroy (struct wl_client *client,
	    struct wl_resource *resource)
{
	wl_resource_destroy (resource);
}

static const struct qa_interface qa_implementation = {
	qa_surface_list,
	qa_destroy
};

static void
bind_qa (struct wl_client *client, void *data,
	 uint32_t version, uint32_t id)
{
	struct wl_resource *resource;

	resource = wl_resource_create (client, &qa_interface,
				       1, id);
	wl_resource_set_implementation (resource, &qa_implementation,
					NULL, NULL);
}

WL_EXPORT int
module_init (struct weston_compositor *compositor,
	     int *argc, char *argv[])
{
	ec = compositor;

	weston_log ("qa-plugin: initialization.\n");

	if (wl_global_create (ec->wl_display, &qa_interface,
			      1, NULL, bind_qa) == NULL)
	{
		weston_log ("qa-plugin: could not bind the \"qa\" interface, exiting...\n");
		return -1;
	}

	return 0;
}