The gears code is moved into a new file gearc.c and the window decoration and management code stays in window.c. A new application 'terminal' is the second user of the windowing code, but doesn't do anything useful yet.dev
parent
dc0f355f0a
commit
0c4457f0c2
@ -1,31 +0,0 @@ |
||||
/*
|
||||
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and associated documentation files (the "Software"), |
||||
* to deal in the Software without restriction, including without limitation |
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
* and/or sell copies of the Software, and to permit persons to whom the |
||||
* Software is furnished to do so, subject to the following conditions: |
||||
*
|
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Software. |
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#ifndef _GEARS_H_ |
||||
#define _GEARS_H_ |
||||
|
||||
struct gears; |
||||
|
||||
struct gears *gears_create(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); |
||||
|
||||
void gears_draw(struct gears *gears, GLfloat angle); |
||||
|
||||
#endif |
@ -0,0 +1,133 @@ |
||||
/*
|
||||
* Copyright © 2008 Kristian Høgsberg |
||||
* |
||||
* 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 <fcntl.h> |
||||
#include <unistd.h> |
||||
#include <math.h> |
||||
#include <time.h> |
||||
#include <cairo.h> |
||||
#include <glib.h> |
||||
|
||||
#include <GL/gl.h> |
||||
#include <eagle.h> |
||||
|
||||
#include "wayland-client.h" |
||||
#include "wayland-glib.h" |
||||
|
||||
#include "cairo-util.h" |
||||
#include "window.h" |
||||
|
||||
static const char gem_device[] = "/dev/dri/card0"; |
||||
static const char socket_name[] = "\0wayland"; |
||||
|
||||
struct terminal { |
||||
struct window *window; |
||||
struct wl_display *display; |
||||
int resize_scheduled; |
||||
}; |
||||
|
||||
static gboolean |
||||
resize_window(void *data) |
||||
{ |
||||
struct terminal *terminal = data; |
||||
|
||||
window_draw(terminal->window); |
||||
wl_display_commit(terminal->display, 0); |
||||
|
||||
return FALSE; |
||||
} |
||||
|
||||
static void |
||||
resize_handler(struct window *window, int32_t width, int32_t height, void *data) |
||||
{ |
||||
struct terminal *terminal = data; |
||||
|
||||
if (!terminal->resize_scheduled) { |
||||
g_idle_add(resize_window, terminal); |
||||
terminal->resize_scheduled = 1; |
||||
} |
||||
} |
||||
|
||||
static void |
||||
acknowledge_handler(struct window *window, uint32_t key, void *data) |
||||
{ |
||||
struct terminal *terminal = data; |
||||
|
||||
terminal->resize_scheduled = 0; |
||||
} |
||||
|
||||
static struct terminal * |
||||
terminal_create(struct wl_display *display, int fd) |
||||
{ |
||||
struct terminal *terminal; |
||||
|
||||
terminal = malloc(sizeof *terminal); |
||||
if (terminal == NULL) |
||||
return terminal; |
||||
|
||||
terminal->window = window_create(display, fd, "Wayland Terminal", |
||||
500, 100, 300, 200); |
||||
terminal->display = display; |
||||
terminal->resize_scheduled = 1; |
||||
|
||||
window_set_resize_handler(terminal->window, resize_handler, terminal); |
||||
window_set_acknowledge_handler(terminal->window, acknowledge_handler, terminal); |
||||
|
||||
return terminal; |
||||
} |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
struct wl_display *display; |
||||
int fd; |
||||
GMainLoop *loop; |
||||
GSource *source; |
||||
struct terminal *terminal; |
||||
|
||||
fd = open(gem_device, O_RDWR); |
||||
if (fd < 0) { |
||||
fprintf(stderr, "drm open failed: %m\n"); |
||||
return -1; |
||||
} |
||||
|
||||
display = wl_display_create(socket_name, sizeof socket_name); |
||||
if (display == NULL) { |
||||
fprintf(stderr, "failed to create display: %m\n"); |
||||
return -1; |
||||
} |
||||
|
||||
loop = g_main_loop_new(NULL, FALSE); |
||||
source = wl_glib_source_new(display); |
||||
g_source_attach(source, NULL); |
||||
|
||||
terminal = terminal_create(display, fd); |
||||
window_draw(terminal->window); |
||||
wl_display_commit(display, 0); |
||||
|
||||
g_main_loop_run(loop); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,67 @@ |
||||
/*
|
||||
* Copyright © 2008 Kristian Høgsberg |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
#ifndef _WINDOW_H_ |
||||
#define _WINDOW_H_ |
||||
|
||||
struct window; |
||||
|
||||
struct rectangle { |
||||
int32_t x; |
||||
int32_t y; |
||||
int32_t width; |
||||
int32_t height; |
||||
}; |
||||
|
||||
typedef void (*window_resize_handler_t)(struct window *window, int32_t width, int32_t height, void *data); |
||||
typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data); |
||||
typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, void *data); |
||||
|
||||
struct window * |
||||
window_create(struct wl_display *display, int fd, |
||||
const char *title, |
||||
int32_t x, int32_t y, int32_t width, int32_t height); |
||||
|
||||
void |
||||
window_set_minimum_size(struct window *window, uint32_t width, int32_t height); |
||||
|
||||
void |
||||
window_draw(struct window *window); |
||||
void |
||||
window_get_child_rectangle(struct window *window, |
||||
struct rectangle *rectangle); |
||||
void |
||||
window_copy(struct window *window, |
||||
struct rectangle *rectangle, |
||||
uint32_t name, uint32_t stride); |
||||
|
||||
void |
||||
window_set_resize_handler(struct window *window, |
||||
window_resize_handler_t handler, void *data); |
||||
void |
||||
window_set_frame_handler(struct window *window, |
||||
window_frame_handler_t handler, void *data); |
||||
void |
||||
window_set_acknowledge_handler(struct window *window, |
||||
window_acknowledge_handler_t handler, void *data); |
||||
|
||||
#endif |
Loading…
Reference in new issue