1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**         @file  mkmodgtk.c
 *         @brief
 *          @date  17/11/2017
 *        @author  François Cerbelle (Fanfan), francois@cerbelle.net
 *     @copyright  Copyright (c) 2017, François Cerbelle
 *
 *   @internal
 *       Compiler  gcc
 *  Last modified  2024-07-31 09:52
 *   Organization  Cerbelle.net
 *        Company  Home
 *
 *   This source code is released for free distribution under the terms of the
 *   GNU General Public License as published by the Free Software Foundation.
 */

#include "mkmod.h"
#include "gettext.h"
#define _(String) gettext (String)

#include <stdio.h>

#include "debug/assert.h"
#include "debug/memory.h"

#include <math.h>
#pragma GCC diagnostic push                             /* save the actual diag context */
#pragma GCC diagnostic ignored "-Wpedantic"             /* locally disable maybe warnings */
#include <gtk/gtk.h>
#pragma GCC diagnostic pop                              /* restore previous diag context */

/* List exposed module functions */
static void mkmod_function();
mkmod_api_t module_api = {
    mkmod_function
};

static moduleinfo_t moduleinfo = {
    "MyGTKModule",
    "MyGTKModule description",
    0,
    1,
    0,
    "First and Lastname",
    "email@address.tld",
    "http://www.mygtkmodule.com",
    "GPLv3"
};

static void
print_hello (GtkWidget *widget,
             gpointer   data)
{
    (void)widget;
    (void)data;
    g_print (_("Hello world from GTK !!!"));
    g_print ("\n");
}

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
    GtkWidget *window;
    GtkWidget *button;
    GtkWidget *box;

    (void)user_data;
    window = gtk_application_window_new (app);
    gtk_window_set_title (GTK_WINDOW (window), "Window");
    gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

    box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
    gtk_widget_set_halign (box, GTK_ALIGN_CENTER);
    gtk_widget_set_valign (box, GTK_ALIGN_CENTER);

    gtk_window_set_child (GTK_WINDOW (window), box);

    button = gtk_button_new_with_label (_("Hello world from GTK !!!"));

    g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
    g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_destroy), window);

    gtk_box_append (GTK_BOX (box), button);

    gtk_window_present (GTK_WINDOW (window));

}

moduleinfo_t* onLoad ()<--- The function 'onLoad' is never used.
{
    DBG_MSG("params()");
    return &moduleinfo;
}

uint8_t onUnload()<--- The function 'onUnload' is never used.
{
    DBG_MSG("params()");
    return 0;
}

static void mkmod_function()
{
    GtkApplication *app;
    DBG_MSG("params()");

    printf(_("Hello from mkmod_function\n"));
    app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
    /* g_application_run (G_APPLICATION (app), argc, argv); */
    g_application_run (G_APPLICATION (app), 0,NULL);
    g_object_unref (app);

}