This is a follow up to the thread that can be found here: [C] [GTK] [Windows 11] [msys2] Trying to produce a working .exe on Windows
I have switched to GTK3 and the compatibility with windows seems to be better because now I am able to input characters into text entry fields.
However, I am unable to backspace or move the position of the cursor with the arrow keys. I am only able to input a character using the keyboard, and then it is “locked” in position.
I can enter the phrase “Hello World” and for each letter character or space I press on the keyboard, the following error is displayed in terminal:
“Gdk-WARNING **: 11:40:40.044: Failed to translate keypress (keycode: 68) for group 0 (A0000409) because we could not load the layout.”
Where, the integer keycode will change depending on which key I press.
The backspace and arrowkeys are completely unresponsive. There are no error messages displayed.
Should backspace or arrow key functionalities be a separate callback? I haven’t been able to figure out. I will attach my code to this thread for clarity on what I’m trying to do.
#include <stdlib.h>
#include <gtk/gtk.h>
#include <stdbool.h>
static GtkTextBuffer *textBuffer = NULL; //textBuffer = gtk_text_buffer_new(NULL);
static GtkTextBuffer *output = NULL; //output = gtk_text_buffer_new(NULL);
static void
click1_cb (GtkButton *btn,
gpointer user_data)
{
GtkTextIter start, end;
gtk_text_buffer_get_bounds(textBuffer, &start, &end);
const GtkTextIter* start2 = &start;
const GtkTextIter* end2 = &end;
char* text = gtk_text_buffer_get_text(textBuffer,start2,end2,false);
gtk_text_buffer_set_text (output, text, -1);
}
int main(int argc, char** argv){
GtkWidget *window, *grid, *textField1, *textField2, *btn, *vbox;
gtk_init(&argc, &argv);
textBuffer = gtk_text_buffer_new(NULL);
output = gtk_text_buffer_new(NULL);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_signal_connect(window,"destroy", G_CALLBACK(gtk_main_quit),NULL);
vbox = gtk_box_new(TRUE, 1);
gtk_container_add(GTK_CONTAINER(window), vbox);
textField1 = gtk_text_view_new_with_buffer(textBuffer);
gtk_box_pack_start(GTK_BOX(vbox), textField1, TRUE, TRUE, 0);
btn = gtk_button_new_with_label ("Execute.");
g_signal_connect (btn, "clicked", G_CALLBACK (click1_cb), NULL);
gtk_box_pack_start(GTK_BOX(vbox), btn, TRUE, TRUE, 0);
textField2 = gtk_text_view_new_with_buffer(output);
gtk_box_pack_start(GTK_BOX(vbox), textField2, TRUE, TRUE, 0);
gtk_widget_show_all(window);
gtk_main();
return 0;
}