tablet-shell: Add a stub tablet-shell client

For a start, this is just to we can run and test the corresponding
compositor plugin and keep it from bit-rotting.
This commit is contained in:
Kristian Høgsberg 2011-11-26 17:36:23 -05:00
parent 53ff2f6672
commit 6336e46e15
3 changed files with 254 additions and 27 deletions

View File

@ -2,7 +2,7 @@ noinst_PROGRAMS = $(clients_programs) \
$(poppler_programs) \
$(simple_clients_programs)
libexec_PROGRAMS = $(desktop_shell)
libexec_PROGRAMS = $(desktop_shell) $(tablet_shell)
if BUILD_SIMPLE_CLIENTS
simple_clients_programs = simple-egl simple-shm
@ -27,6 +27,7 @@ clients_programs = \
eventdemo
desktop_shell = wayland-desktop-shell
tablet_shell = wayland-tablet-shell
noinst_LIBRARIES = libtoytoolkit.a
@ -82,11 +83,19 @@ wayland_desktop_shell_SOURCES = \
desktop-shell-protocol.c
wayland_desktop_shell_LDADD = $(toolkit_libs)
wayland_tablet_shell_SOURCES = \
tablet-shell.c \
tablet-shell-client-protocol.h \
tablet-shell-protocol.c
wayland_tablet_shell_LDADD = $(toolkit_libs)
BUILT_SOURCES = \
screenshooter-client-protocol.h \
screenshooter-protocol.c \
desktop-shell-client-protocol.h \
desktop-shell-protocol.c
desktop-shell-protocol.c \
tablet-shell-client-protocol.h \
tablet-shell-protocol.c
CLEANFILES = $(BUILT_SOURCES)
endif

216
clients/tablet-shell.c Normal file
View File

@ -0,0 +1,216 @@
/*
* Copyright © 2011 Intel Corporation
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "window.h"
#include "cairo-util.h"
#include "tablet-shell-client-protocol.h"
struct tablet_shell {
struct display *display;
struct tablet_shell *tablet_shell;
struct rectangle allocation;
struct window *lockscreen;
struct window *switcher;
struct window *homescreen;
};
static void
draw_stub(struct window *window, const char *caption)
{
cairo_surface_t *surface;
struct rectangle allocation;
const int margin = 50, radius = 10;
cairo_text_extents_t extents;
cairo_t *cr;
window_draw(window);
window_get_child_allocation(window, &allocation);
surface = window_get_surface(window);
cr = cairo_create(surface);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.4);
cairo_paint(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
rounded_rect(cr, allocation.x + margin, allocation.y + margin,
allocation.x + allocation.width - margin,
allocation.y + allocation.height - margin, radius);
cairo_set_line_width(cr, 6);
cairo_stroke(cr);
cairo_select_font_face(cr, "Sans",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, 40);
cairo_text_extents(cr, caption, &extents);
cairo_move_to(cr,
allocation.x + (allocation.width - extents.width) / 2,
allocation.y + (allocation.height - extents.height) / 2);
cairo_show_text(cr, caption);
cairo_surface_flush(surface);
cairo_surface_destroy(surface);
window_flush(window);
}
static void
homescreen_draw(struct tablet_shell *shell)
{
draw_stub(shell->homescreen, "Homescreen Stub");
}
static void
lockscreen_draw(struct tablet_shell *shell)
{
draw_stub(shell->lockscreen, "Lockscreen Stub");
}
static int
lockscreen_motion_handler(struct window *window,
struct input *input, uint32_t time,
int32_t x, int32_t y,
int32_t sx, int32_t sy, void *data)
{
return POINTER_LEFT_PTR;
}
static void
lockscreen_button_handler(struct window *window,
struct input *input, uint32_t time,
int button, int state, void *data)
{
struct tablet_shell *shell = data;
window_destroy(shell->lockscreen);
shell->lockscreen = NULL;
}
static void
show_lockscreen(void *data, struct tablet_shell *tablet_shell)
{
struct tablet_shell *shell = data;
shell->lockscreen = window_create(shell->display,
shell->allocation.width,
shell->allocation.height);
window_set_user_data(shell->lockscreen, shell);
window_set_decoration(shell->lockscreen, 0);
window_set_custom(shell->lockscreen);
window_set_button_handler(shell->lockscreen,
lockscreen_button_handler);
window_set_motion_handler(shell->lockscreen,
lockscreen_motion_handler);
tablet_shell_set_lockscreen(shell->tablet_shell,
window_get_wl_surface(shell->lockscreen));
lockscreen_draw(shell);
}
static void
show_switcher(void *data, struct tablet_shell *tablet_shell)
{
struct tablet_shell *shell = data;
shell->switcher = window_create(shell->display, 0, 0);
window_set_user_data(shell->switcher, shell);
window_set_decoration(shell->switcher, 0);
window_set_custom(shell->switcher);
tablet_shell_set_switcher(shell->tablet_shell,
window_get_wl_surface(shell->switcher));
}
static void
hide_switcher(void *data, struct tablet_shell *tablet_shell)
{
}
static const struct tablet_shell_listener tablet_shell_listener = {
show_lockscreen,
show_switcher,
hide_switcher
};
static struct tablet_shell *
tablet_shell_create(struct display *display, uint32_t id)
{
struct tablet_shell *shell;
struct output *output;
shell = malloc(sizeof *shell);
shell->display = display;
shell->tablet_shell =
wl_display_bind(display_get_display(display),
id, &tablet_shell_interface);
tablet_shell_add_listener(shell->tablet_shell,
&tablet_shell_listener, shell);
output = display_get_output(display);
output_get_allocation(output, &shell->allocation);
shell->homescreen = window_create(display,
shell->allocation.width,
shell->allocation.height);
window_set_user_data(shell->homescreen, shell);
window_set_decoration(shell->homescreen, 0);
window_set_custom(shell->homescreen);
tablet_shell_set_homescreen(shell->tablet_shell,
window_get_wl_surface(shell->homescreen));
homescreen_draw(shell);
return shell;
}
int main(int argc, char *argv[])
{
struct display *display;
uint32_t id;
fprintf(stderr, "tablet shell client running\n");
display = display_create(&argc, &argv, NULL);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
}
wl_display_roundtrip(display_get_display(display));
id = wl_display_get_global(display_get_display(display),
"tablet_shell", 1);
tablet_shell_create(display, id);
display_run(display);
return 0;
}

View File

@ -100,7 +100,8 @@ tablet_shell_sigchld(struct wlsc_process *process, int status)
shell->process.pid = 0;
fprintf(stderr, "meego-ux-daemon crashed, exit code %d\n", status);
fprintf(stderr,
"wayland-tablet-daemon crashed, exit code %d\n", status);
}
static void
@ -212,8 +213,7 @@ tablet_shell_map(struct wlsc_shell *base, struct wlsc_surface *surface,
surface->y = 0;
if (surface == shell->lockscreen_surface) {
wlsc_compositor_fade(shell->compositor, 0.0);
wlsc_compositor_wake(shell->compositor);
/* */
} else if (surface == shell->switcher_surface) {
/* */
} else if (surface == shell->home_surface) {
@ -263,14 +263,10 @@ tablet_shell_set_lockscreen(struct wl_client *client,
{
struct tablet_shell *shell = resource->data;
struct wlsc_surface *es = surface_resource->data;
struct wlsc_input_device *device =
(struct wlsc_input_device *) shell->compositor->input_device;
es->x = 0;
es->y = 0;
wlsc_surface_activate(es, device, wlsc_compositor_get_time());
shell->lockscreen_surface = es;
shell->lockscreen_listener.func = handle_lockscreen_surface_destroy;
wl_list_insert(es->surface.resource.destroy_listener_list.prev,
&shell->lockscreen_listener.link);
@ -295,8 +291,6 @@ tablet_shell_set_switcher(struct wl_client *client,
struct wl_resource *surface_resource)
{
struct tablet_shell *shell = resource->data;
struct wlsc_input_device *device =
(struct wlsc_input_device *) shell->compositor->input_device;
struct wlsc_surface *es = surface_resource->data;
/* FIXME: Switcher should be centered and the compositor
@ -307,8 +301,6 @@ tablet_shell_set_switcher(struct wl_client *client,
shell->switcher_surface->x = 0;
shell->switcher_surface->y = 0;
wlsc_surface_activate(es, device, wlsc_compositor_get_time());
shell->switcher_listener.func = handle_switcher_surface_destroy;
wl_list_insert(es->surface.resource.destroy_listener_list.prev,
&shell->switcher_listener.link);
@ -320,15 +312,10 @@ tablet_shell_set_homescreen(struct wl_client *client,
struct wl_resource *surface_resource)
{
struct tablet_shell *shell = resource->data;
struct wlsc_input_device *device =
(struct wlsc_input_device *) shell->compositor->input_device;
shell->home_surface = surface_resource->data;
shell->home_surface->x = 0;
shell->home_surface->y = 0;
wlsc_surface_activate(shell->home_surface, device,
wlsc_compositor_get_time());
}
static void
@ -478,6 +465,7 @@ static const struct tablet_shell_interface tablet_shell_implementation = {
static void
launch_ux_daemon(struct tablet_shell *shell)
{
const char *shell_exe = LIBEXECDIR "/wayland-tablet-shell";
struct wlsc_compositor *compositor = shell->compositor;
char s[32];
int sv[2], flags;
@ -500,9 +488,7 @@ launch_ux_daemon(struct tablet_shell *shell)
snprintf(s, sizeof s, "%d", sv[1]);
setenv("WAYLAND_SOCKET", s, 1);
setenv("QT_QPA_PLATFORM", "waylandgl", 1);
if (execl("/usr/libexec/meego-ux-daemon",
"/usr/libexec/meego-ux-daemon", NULL) < 0)
if (execl(shell_exe, shell_exe, NULL) < 0)
fprintf(stderr, "exec failed: %m\n");
exit(-1);
@ -535,6 +521,13 @@ toggle_switcher(struct tablet_shell *shell)
}
}
static void
tablet_shell_activate(struct wlsc_shell *base, struct wlsc_surface *es,
struct wlsc_input_device *device, uint32_t time)
{
wlsc_surface_activate(es, device, time);
}
static void
tablet_shell_lock(struct wlsc_shell *base)
{
@ -632,6 +625,11 @@ home_key_binding(struct wl_input_device *device, uint32_t time,
}
}
static void
destroy_tablet_shell(struct wl_resource *resource)
{
}
static void
bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
@ -642,8 +640,15 @@ bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
* tries to access the object?. */
return;
shell->resource.client = client;
shell->resource.object.id = id;
shell->resource.object.interface = &tablet_shell_interface;
shell->resource.object.implementation =
(void (**)(void)) &tablet_shell_implementation;
shell->resource.client = client;
shell->resource.data = shell;
shell->resource.destroy = destroy_tablet_shell;
wl_client_add_resource(client, &shell->resource);
}
void
@ -662,13 +667,9 @@ shell_init(struct wlsc_compositor *compositor)
memset(shell, 0, sizeof *shell);
shell->compositor = compositor;
shell->resource.object.interface = &tablet_shell_interface;
shell->resource.object.implementation =
(void (**)(void)) &tablet_shell_implementation;
/* FIXME: This will make the object available to all clients. */
wl_display_add_global(compositor->wl_display,
&wl_shell_interface, shell, bind_shell);
&tablet_shell_interface, shell, bind_shell);
loop = wl_display_get_event_loop(compositor->wl_display);
shell->long_press_source =
@ -687,6 +688,7 @@ shell_init(struct wlsc_compositor *compositor)
compositor->shell = &shell->shell;
shell->shell.activate = tablet_shell_activate;
shell->shell.lock = tablet_shell_lock;
shell->shell.unlock = tablet_shell_unlock;
shell->shell.map = tablet_shell_map;