GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Enumerations | Functions
gp_x11.h File Reference

A X11 backend. More...

#include <backends/gp_backend.h>

Go to the source code of this file.

Enumerations

enum  gp_x11_flags { GP_X11_USE_ROOT_WIN = 0x01 , GP_X11_CREATE_ROOT_WIN = 0x02 , GP_X11_FULLSCREEN = 0x04 , GP_X11_DISABLE_SHM = 0x08 }
 A X11 backend init flags. More...
 

Functions

gp_backendgp_x11_init (const char *display, int x, int y, unsigned int w, unsigned int h, const char *caption, enum gp_x11_flags flags)
 X11 backend initialization.
 

Detailed Description

A X11 backend.

X11 backend supports multiple windows, you can call the init function multiple times, each time you get a backend representing a new X11 window that will share the underlying X11 server connection.

// SPDX-License-Identifier: GPL-2.1-or-later
/*
* Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz>
*/
/* X11 example with two windows. */
#include <stdio.h>
#include <gfxprim.h>
static void redraw(struct gp_pixmap *pixmap)
{
gp_pixel white_pixel, black_pixel;
black_pixel = gp_rgb_to_pixmap_pixel(0x00, 0x00, 0x00, pixmap);
white_pixel = gp_rgb_to_pixmap_pixel(0xff, 0xff, 0xff, pixmap);
gp_fill(pixmap, black_pixel);
gp_line(pixmap, 0, 0, pixmap->w - 1, pixmap->h - 1, white_pixel);
gp_line(pixmap, 0, pixmap->h - 1, pixmap->w - 1, 0, white_pixel);
}
static int ev_loop(struct gp_backend *backend, const char *name)
{
gp_event *ev;
if (backend == NULL)
return 0;
while ((ev = gp_backend_get_event(backend))) {
printf("-------------------------- %s\n", name);
switch (ev->type) {
case GP_EV_KEY:
switch (ev->val) {
case GP_KEY_ESC:
case GP_KEY_Q:
gp_backend_exit(backend);
return 1;
break;
}
break;
case GP_EV_SYS:
switch (ev->code) {
redraw(backend->pixmap);
gp_backend_flip(backend);
break;
gp_backend_exit(backend);
return 1;
break;
}
break;
}
printf("-----------------------------\n");
}
return 0;
}
int main(void)
{
gp_backend *win_1, *win_2;
win_1 = gp_x11_init(NULL, 0, 0, 300, 300, "win 1", 0);
win_2 = gp_x11_init(NULL, 0, 0, 300, 300, "win 2", 0);
if (win_1 == NULL || win_2 == NULL) {
return 1;
}
/* Update the windows */
redraw(win_1->pixmap);
redraw(win_2->pixmap);
for (;;) {
/*
* Wait for backend event.
*
* Either window is fine as they share connection.
*/
gp_backend *b = win_1 ? win_1 : win_2;
if (b == NULL)
return 0;
gp_backend_wait(b);
if (ev_loop(win_1, "win 1"))
win_1 = NULL;
if (ev_loop(win_2, "win 2"))
win_2 = NULL;
}
return 0;
}
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33
static void gp_backend_flip(gp_backend *self)
Copies whole backend pixmap to a display.
Definition gp_backend.h:208
int gp_backend_resize_ack(gp_backend *self)
Resize acknowledge.
void gp_backend_exit(gp_backend *self)
Exits the backend.
@ GP_EV_SYS_RESIZE
User resized the applicaton window.
Definition gp_event.h:86
@ GP_EV_SYS_QUIT
User requested application to quit.
Definition gp_event.h:78
void gp_ev_dump(gp_event *ev)
Dumps event into a stdout.
@ GP_EV_SYS
A system events, window close, resize, etc.
Definition gp_event.h:33
@ GP_EV_KEY
A key or button press event.
Definition gp_event.h:27
@ GP_KEY_Q
Key Q.
@ GP_KEY_ESC
Key escape.
gp_backend * gp_x11_init(const char *display, int x, int y, unsigned int w, unsigned int h, const char *caption, enum gp_x11_flags flags)
X11 backend initialization.
void gp_line(gp_pixmap *pixmap, gp_coord x0, gp_coord y0, gp_coord x1, gp_coord y1, gp_pixel pixel)
Classical Bresenham line drawing algorithm.
void gp_fill(gp_pixmap *pixmap, gp_pixel val)
Fills pixmap with given pixel value.
A backend.
Definition gp_backend.h:72
gp_pixmap * pixmap
Pointer to pixmap app should draw to.
Definition gp_backend.h:81
An input event.
Definition gp_event.h:153
int32_t val
A generic integer value.
Definition gp_event.h:161
uint16_t code
enum gp_event_*_code
Definition gp_event.h:157
uint16_t type
enum gp_event_type
Definition gp_event.h:155
A pixmap buffer.
Definition gp_pixmap.h:33
uint32_t h
Pixmap height in pixels.
Definition gp_pixmap.h:46
uint32_t w
Pixmap width in pixels.
Definition gp_pixmap.h:44

Definition in file gp_x11.h.

Enumeration Type Documentation

◆ gp_x11_flags

A X11 backend init flags.

Enumerator
GP_X11_USE_ROOT_WIN 

When set, w and h is ignored and root window is used.

GP_X11_CREATE_ROOT_WIN 

Create new borderless window above the root window.

GP_X11_FULLSCREEN 

Start fullscreen.

GP_X11_DISABLE_SHM 

Do not use MIT SHM even if available.

Definition at line 22 of file gp_x11.h.

Function Documentation

◆ gp_x11_init()

gp_backend * gp_x11_init ( const char *  display,
int  x,
int  y,
unsigned int  w,
unsigned int  h,
const char *  caption,
enum gp_x11_flags  flags 
)

X11 backend initialization.

Parameters
displayA X11 display. If NULL default is used.
xA window X offset.
yA window Y offset.
wA window width.
hA window height.
captionA window caption.
flagsA bitwise combination of enum gp_x11_flags.
Returns
A newly allocated backend, or NULL in a case of a failure, or if X11 support wasn't compiled in.