#ifndef __ROCCAT_MACRO_KEYSTROKES_H__
#define __ROCCAT_MACRO_KEYSTROKES_H__

/*
 * This file is part of roccat-tools.
 *
 * roccat-tools is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * roccat-tools is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with roccat-tools. If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>

G_BEGIN_DECLS

typedef struct _RoccatMacroKeystroke RoccatMacroKeystroke;
typedef struct _RoccatMacroKeystrokes RoccatMacroKeystrokes;

enum {
	ROCCAT_MACRO_KEYSTROKES_NUM = 512,
	ROCCAT_MACRO_KEYSTROKE_PERIOD_MAX = G_MAXUINT16,
};

struct _RoccatMacroKeystroke {
	guint8 key;
	guint8 action;
	guint16 period;
} __attribute__ ((packed));

typedef enum {
	ROCCAT_MACRO_KEYSTROKE_KEY_BUTTON_LEFT = 0xf0,
	ROCCAT_MACRO_KEYSTROKE_KEY_BUTTON_RIGHT = 0xf1,
	ROCCAT_MACRO_KEYSTROKE_KEY_BUTTON_MIDDLE = 0xf2,
} RoccatMacroKeystrokeKey;

typedef enum {
	ROCCAT_MACRO_KEYSTROKE_ACTION_PRESS = 0,
	ROCCAT_MACRO_KEYSTROKE_ACTION_RELEASE = 1
} RoccatMacroKeystrokeAction;

static inline guint16 roccat_macro_keystroke_get_period(RoccatMacroKeystroke const *keystroke) {
	return GUINT16_FROM_LE(keystroke->period);
}

static inline void roccat_macro_keystroke_set_period(RoccatMacroKeystroke *keystroke, guint16 new_value) {
	keystroke->period = GUINT16_TO_LE(new_value);
}

/*!
 * \brief unified button info for roccat_macro.ini
 */
struct _RoccatMacroKeystrokes {
	guint16 count;
	RoccatMacroKeystroke keystrokes[ROCCAT_MACRO_KEYSTROKES_NUM];
	guint8 loop;
} __attribute__ ((packed));

static inline guint16 roccat_macro_keystrokes_get_count(RoccatMacroKeystrokes const *keystrokes) {
	return GUINT16_FROM_LE(keystrokes->count);
}

static inline void roccat_macro_keystrokes_set_count(RoccatMacroKeystrokes *keystrokes, guint16 new_value) {
	keystrokes->count = GUINT16_TO_LE(new_value);
}

void roccat_macro_keystrokes_init(RoccatMacroKeystrokes *keystrokes);
RoccatMacroKeystrokes *roccat_key_file_get_roccat_macro_keystrokes(GKeyFile *key_file,
		gchar const *macro_set_name, gchar const *macro_name,
		GError **error);
gboolean roccat_macro_keystrokes_have_mouse_keystroke(RoccatMacroKeystrokes const *keystrokes);
RoccatMacroKeystrokes *roccat_macro_keystrokes_new(void);
void roccat_macro_keystrokes_free(RoccatMacroKeystrokes *keystrokes);
void roccat_macro_keystrokes_copy(RoccatMacroKeystrokes const *from, RoccatMacroKeystrokes *to);
RoccatMacroKeystrokes *roccat_macro_keystrokes_dup(RoccatMacroKeystrokes const *old);
gboolean roccat_macro_keystrokes_add(RoccatMacroKeystrokes *keystrokes, RoccatMacroKeystroke const *keystroke);
void roccat_macro_keystrokes_clear(RoccatMacroKeystrokes *keystrokes);

G_END_DECLS

#endif
