/*
Copyright (c) 2015, Mislav Bozicevic <misbozice@foi.hr>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, 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 PROZOR_H
#define PROZOR_H

#include <GL/glx.h>
#include <GL/gl.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/XKBlib.h>
#include <X11/keysymdef.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>

#define BEZ_PROBLEMA 0
#define BILO_PROBLEMA 1

struct prozor_t{
	Display *konekcija;
	int ekran;
	XVisualInfo *info;
	GLXContext kontekst;
	Window roditelj;
	Window prozor;
	Colormap boje;
	XSetWindowAttributes postavke;
	unsigned int sirina;
	unsigned int visina;
	char radi;
	pthread_t dretva;
	void (*prikaz)(void);
	char prikaz_registriran;
	void (*tipkovnica)(char);
	char tipkovnica_registriran;
	pthread_t dretva_timer;
	void (*timer)(void);
	char timer_registriran;
	time_t timer_zastoj_sekunde;
	long timer_zastoj_nanosekunde;
};

static pthread_mutex_t KRITICNI = PTHREAD_MUTEX_INITIALIZER;

struct prozor_t* prozor_inicijaliziraj(const unsigned int, const unsigned int,
	const char *);
void prozor_osvjezi(struct prozor_t*);
void prozor_registriraj_callback_prikaz(void (*)(void), struct prozor_t *);
void prozor_registriraj_callback_tipkovnica(void (*)(char),
	struct prozor_t *);
void prozor_registriraj_callback_timer(void (*)(void), time_t, long,
	struct prozor_t *);
void prozor_pokreni_petlju(struct prozor_t*);
void* prozor_glavna_petlja(void*);
void prozor_zavrsi_petlju(struct prozor_t*);
void* prozor_timer_petlja(void*);
void prozor_oslobodi(struct prozor_t*);

#endif