Commit cea814c38b8326606b4e4a41aae00b829b34eb8c
1 parent
bc22973f
Exists in
master
and in
1 other branch
refactoring pfkey accelerators.
Showing
7 changed files
with
46 additions
and
194 deletions
Show diff stats
src/dialogs/settings/accelerator.c
| ... | ... | @@ -444,27 +444,6 @@ static void alternative_edited(GtkCellRendererAccel G_GNUC_UNUSED(*renderer), gc |
| 444 | 444 | } |
| 445 | 445 | gtk_tree_path_free(tree_path); |
| 446 | 446 | |
| 447 | - if(accel && accel->type == V3270_ACCELERATOR_TYPE_PFKEY) | |
| 448 | - { | |
| 449 | - GtkWidget * dialog = | |
| 450 | - gtk_message_dialog_new_with_markup( | |
| 451 | - GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), | |
| 452 | - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 453 | - GTK_MESSAGE_ERROR, | |
| 454 | - GTK_BUTTONS_CANCEL, | |
| 455 | - _( "The action \"%s\" can't manage alternative keys" ), | |
| 456 | - v3270_accelerator_get_description(accel) | |
| 457 | - ); | |
| 458 | - | |
| 459 | - gtk_window_set_title(GTK_WINDOW(dialog),_("Rejected by action")); | |
| 460 | - gtk_widget_show_all(dialog); | |
| 461 | - | |
| 462 | - g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
| 463 | - g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL); | |
| 464 | - | |
| 465 | - return; | |
| 466 | - } | |
| 467 | - | |
| 468 | 447 | // Call the common validation. |
| 469 | 448 | change_accel(widget, path, accel_key, mask, ALTERNATIVE_VALUE, ALTERNATIVE_MASK); |
| 470 | 449 | } |
| ... | ... | @@ -490,17 +469,8 @@ void load(GtkWidget *widget, GtkWidget *terminal) |
| 490 | 469 | |
| 491 | 470 | if(ix < G_N_ELEMENTS(keymaps)) |
| 492 | 471 | { |
| 493 | - if(accel->type == V3270_ACCELERATOR_TYPE_PFKEY) | |
| 494 | - { | |
| 495 | - keymaps[ix].key = GDK_F1 + (((V3270PFKeyAccelerator *)accel)->keycode - 1); | |
| 496 | - keymaps[ix].mods = 0; | |
| 497 | - } | |
| 498 | - else | |
| 499 | - { | |
| 500 | - keymaps[ix].key = accel->key; | |
| 501 | - keymaps[ix].mods = accel->mods; | |
| 502 | - } | |
| 503 | - | |
| 472 | + keymaps[ix].key = accel->key; | |
| 473 | + keymaps[ix].mods = accel->mods; | |
| 504 | 474 | ix++; |
| 505 | 475 | } |
| 506 | 476 | |
| ... | ... | @@ -560,44 +530,19 @@ static gboolean add_accel(GtkTreeModel *model, GtkTreePath G_GNUC_UNUSED(*path), |
| 560 | 530 | // Allways create the "main" accelerator to keep the action active. |
| 561 | 531 | V3270Accelerator * acc = v3270_accelerator_clone(accel); |
| 562 | 532 | |
| 563 | - if(acc->type == V3270_ACCELERATOR_TYPE_PFKEY) { | |
| 564 | - | |
| 565 | - if(keymap[0].mods) { | |
| 566 | - g_warning("PFKey accelerator can't manage modifiers"); | |
| 567 | - } | |
| 568 | - | |
| 569 | - int pfkey = (keymap[0].key - GDK_F1) + 1; | |
| 570 | - | |
| 571 | - if(pfkey < 0 || pfkey > 22) { | |
| 572 | - | |
| 573 | - g_warning("Invalid pfkey code: %d",pfkey); | |
| 533 | + acc->key = keymap[0].key; | |
| 534 | + acc->mods = keymap[0].mods; | |
| 535 | + *accelerators = g_slist_prepend(*accelerators,acc); | |
| 574 | 536 | |
| 575 | - } else { | |
| 576 | - | |
| 577 | - ((V3270PFKeyAccelerator *) acc)->keycode = (unsigned short) pfkey; | |
| 578 | - | |
| 579 | - } | |
| 580 | - | |
| 581 | - *accelerators = g_slist_prepend(*accelerators,acc); | |
| 582 | - | |
| 583 | - } else { | |
| 584 | - | |
| 585 | - acc->key = keymap[0].key; | |
| 586 | - acc->mods = keymap[0].mods; | |
| 537 | + // The alternative one is created only when set. | |
| 538 | + if(keymap[1].key) | |
| 539 | + { | |
| 540 | + acc = v3270_accelerator_clone(accel); | |
| 541 | + acc->key = keymap[1].key; | |
| 542 | + acc->mods = keymap[1].mods; | |
| 587 | 543 | *accelerators = g_slist_prepend(*accelerators,acc); |
| 588 | - | |
| 589 | - // The alternative one is created only when set. | |
| 590 | - if(keymap[1].key) | |
| 591 | - { | |
| 592 | - acc = v3270_accelerator_clone(accel); | |
| 593 | - acc->key = keymap[1].key; | |
| 594 | - acc->mods = keymap[1].mods; | |
| 595 | - *accelerators = g_slist_prepend(*accelerators,acc); | |
| 596 | - } | |
| 597 | - | |
| 598 | 544 | } |
| 599 | 545 | |
| 600 | - | |
| 601 | 546 | return FALSE; |
| 602 | 547 | } |
| 603 | 548 | |
| ... | ... | @@ -617,10 +562,7 @@ void apply(GtkWidget *s, GtkWidget *t) |
| 617 | 562 | if(terminal->accelerators) |
| 618 | 563 | g_slist_free_full(terminal->accelerators,g_free); |
| 619 | 564 | |
| 620 | - terminal->accelerators = accelerators; | |
| 621 | - | |
| 622 | - // And sort it. | |
| 623 | - v3270_accelerator_map_sort(terminal); | |
| 565 | + terminal->accelerators = v3270_accelerator_map_sort(accelerators); | |
| 624 | 566 | |
| 625 | 567 | } |
| 626 | 568 | ... | ... |
src/include/internals.h
| ... | ... | @@ -158,7 +158,6 @@ |
| 158 | 158 | V3270_ACCELERATOR_TYPE_INTERNAL, ///< @brief Accelerator is internal. |
| 159 | 159 | V3270_ACCELERATOR_TYPE_LIB3270_ACTION, ///< @brief Accelerator is a lib3270 action. |
| 160 | 160 | V3270_ACCELERATOR_TYPE_LIB3270_TOGGLE, ///< @brief Accelerator is a lib3270 toggle. |
| 161 | - V3270_ACCELERATOR_TYPE_PFKEY, ///< @brief Accelerator is a PFKey redirector. | |
| 162 | 161 | V3270_ACCELERATOR_TYPE_CUSTOM, ///< @brief Custom (application based) accelerator. |
| 163 | 162 | }; |
| 164 | 163 | |
| ... | ... | @@ -177,24 +176,6 @@ |
| 177 | 176 | const gchar *name; |
| 178 | 177 | } V3270CustomAccelerator; |
| 179 | 178 | |
| 180 | - typedef struct _V3270PFKeyAccelerator | |
| 181 | - { | |
| 182 | - struct _V3270Accelerator parent; | |
| 183 | - const gchar *name; | |
| 184 | - const gchar *description; | |
| 185 | - unsigned short keycode; | |
| 186 | - } V3270PFKeyAccelerator; | |
| 187 | - | |
| 188 | - /* | |
| 189 | - typedef enum v3270_toggleable_dialog | |
| 190 | - { | |
| 191 | - V3270_TOGGLEABLE_DIALOG_PASTE_FAILED, | |
| 192 | - | |
| 193 | - V3270_TOGGLEABLE_DIALOG_CUSTOM | |
| 194 | - } V3270_TOGGLEABLE_DIALOG; | |
| 195 | - | |
| 196 | - G_GNUC_INTERNAL GtkResponseType v3270_popup_toggleable_dialog(GtkWidget *widget, V3270_TOGGLEABLE_DIALOG id, const gchar *title, const gchar *summary, const gchar *body, const gchar *first_button_text, ...) G_GNUC_NULL_TERMINATED; | |
| 197 | - */ | |
| 198 | 179 | |
| 199 | 180 | #if GTK_CHECK_VERSION(3,12,0) |
| 200 | 181 | G_GNUC_INTERNAL GtkHeaderBar * v3270_dialog_get_header_bar(GtkWidget * widget); |
| ... | ... | @@ -387,8 +368,8 @@ G_GNUC_INTERNAL void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned |
| 387 | 368 | G_GNUC_INTERNAL void v3270_update_toggle(GtkWidget *widget, LIB3270_TOGGLE_ID id, unsigned char value, const char *name); |
| 388 | 369 | |
| 389 | 370 | // Accelerators |
| 390 | - G_GNUC_INTERNAL void v3270_accelerator_map_sort(v3270 *widget); | |
| 391 | - G_GNUC_INTERNAL void v3270_init_accelerators(v3270 *widget); | |
| 371 | + G_GNUC_INTERNAL GSList * v3270_accelerator_map_sort(GSList * accelerators); | |
| 372 | + G_GNUC_INTERNAL GSList * v3270_accelerator_map_load_default(GSList * accelerators); | |
| 392 | 373 | |
| 393 | 374 | G_END_DECLS |
| 394 | 375 | ... | ... |
src/terminal/keyboard/accelerator.c
| ... | ... | @@ -51,15 +51,6 @@ |
| 51 | 51 | } |
| 52 | 52 | break; |
| 53 | 53 | |
| 54 | - case V3270_ACCELERATOR_TYPE_PFKEY: | |
| 55 | - { | |
| 56 | - V3270PFKeyAccelerator * customAccel = g_new0(V3270PFKeyAccelerator,1); | |
| 57 | - *customAccel = *((V3270PFKeyAccelerator *) accel); | |
| 58 | - customAccel->parent.arg = (gconstpointer) customAccel; | |
| 59 | - rc = (V3270Accelerator *) customAccel; | |
| 60 | - } | |
| 61 | - break; | |
| 62 | - | |
| 63 | 54 | default: |
| 64 | 55 | rc = g_new0(V3270Accelerator,1); |
| 65 | 56 | *rc = *accel; |
| ... | ... | @@ -176,14 +167,6 @@ |
| 176 | 167 | description = g_dgettext(GETTEXT_PACKAGE,property->summary); |
| 177 | 168 | break; |
| 178 | 169 | |
| 179 | - case V3270_ACCELERATOR_TYPE_PFKEY: | |
| 180 | - debug("%s","V3270_ACCELERATOR_TYPE_PFKEY"); | |
| 181 | - | |
| 182 | - if( ((V3270PFKeyAccelerator *)accel)->description ) | |
| 183 | - description = g_dgettext(GETTEXT_PACKAGE,((V3270PFKeyAccelerator *)accel)->description); | |
| 184 | - | |
| 185 | - break; | |
| 186 | - | |
| 187 | 170 | } |
| 188 | 171 | |
| 189 | 172 | debug("%s=%s",__FUNCTION__,description); |
| ... | ... | @@ -218,14 +201,6 @@ |
| 218 | 201 | description = g_dgettext(GETTEXT_PACKAGE,property->summary); |
| 219 | 202 | break; |
| 220 | 203 | |
| 221 | - case V3270_ACCELERATOR_TYPE_PFKEY: | |
| 222 | - debug("%s","V3270_ACCELERATOR_TYPE_PFKEY"); | |
| 223 | - | |
| 224 | - if( ((V3270PFKeyAccelerator *)accel)->description ) | |
| 225 | - description = g_dgettext(GETTEXT_PACKAGE,((V3270PFKeyAccelerator *)accel)->description); | |
| 226 | - | |
| 227 | - break; | |
| 228 | - | |
| 229 | 204 | } |
| 230 | 205 | |
| 231 | 206 | debug("%s=%s",__FUNCTION__,description); |
| ... | ... | @@ -299,9 +274,6 @@ |
| 299 | 274 | case V3270_ACCELERATOR_TYPE_CUSTOM: |
| 300 | 275 | return ((V3270CustomAccelerator *) accel)->name; |
| 301 | 276 | |
| 302 | - case V3270_ACCELERATOR_TYPE_PFKEY: | |
| 303 | - return ((V3270PFKeyAccelerator *) accel)->name; | |
| 304 | - | |
| 305 | 277 | } |
| 306 | 278 | |
| 307 | 279 | return NULL; | ... | ... |
src/terminal/keyboard/init.c
| ... | ... | @@ -68,6 +68,7 @@ |
| 68 | 68 | return lib3270_toggle(v3270_get_session(widget),action->id); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | + /* | |
| 71 | 72 | static int fire_pfkey_action(GtkWidget *widget, V3270PFKeyAccelerator *accel) |
| 72 | 73 | { |
| 73 | 74 | debug("%s accel=%p",__FUNCTION__,accel); |
| ... | ... | @@ -75,12 +76,13 @@ |
| 75 | 76 | |
| 76 | 77 | return lib3270_pfkey(v3270_get_session(widget),(int) accel->keycode); |
| 77 | 78 | } |
| 79 | + */ | |
| 78 | 80 | |
| 79 | - void v3270_init_accelerators(v3270 *widget) | |
| 81 | + GSList * v3270_accelerator_map_load_default(GSList * accelerators) | |
| 80 | 82 | { |
| 81 | 83 | size_t ix; |
| 82 | 84 | |
| 83 | - // Create accelerators for lib3270 actions. | |
| 85 | + // Create accelerators for lib3270 actions. | |
| 84 | 86 | { |
| 85 | 87 | const LIB3270_ACTION * actions = lib3270_get_actions(); |
| 86 | 88 | |
| ... | ... | @@ -105,7 +107,7 @@ |
| 105 | 107 | |
| 106 | 108 | v3270_accelerator_parse(accelerator,keys[key]); |
| 107 | 109 | |
| 108 | - widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); | |
| 110 | + accelerators = g_slist_prepend(accelerators,accelerator); | |
| 109 | 111 | |
| 110 | 112 | } |
| 111 | 113 | |
| ... | ... | @@ -119,7 +121,7 @@ |
| 119 | 121 | accelerator->type = V3270_ACCELERATOR_TYPE_LIB3270_ACTION; |
| 120 | 122 | accelerator->arg = (gconstpointer) &actions[ix]; |
| 121 | 123 | accelerator->activate = G_CALLBACK(fire_lib3270_action); |
| 122 | - widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); | |
| 124 | + accelerators = g_slist_prepend(accelerators,accelerator); | |
| 123 | 125 | |
| 124 | 126 | } |
| 125 | 127 | |
| ... | ... | @@ -141,7 +143,7 @@ |
| 141 | 143 | |
| 142 | 144 | v3270_accelerator_parse(accelerator,toggles[ix].key); |
| 143 | 145 | |
| 144 | - widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); | |
| 146 | + accelerators = g_slist_prepend(accelerators,accelerator); | |
| 145 | 147 | |
| 146 | 148 | } |
| 147 | 149 | |
| ... | ... | @@ -169,7 +171,7 @@ |
| 169 | 171 | |
| 170 | 172 | v3270_accelerator_parse(accelerator,keys[key]); |
| 171 | 173 | |
| 172 | - widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); | |
| 174 | + accelerators = g_slist_prepend(accelerators,accelerator); | |
| 173 | 175 | |
| 174 | 176 | } |
| 175 | 177 | |
| ... | ... | @@ -184,7 +186,7 @@ |
| 184 | 186 | accelerator->arg = (gconstpointer) &actions[ix]; |
| 185 | 187 | accelerator->activate = G_CALLBACK(actions[ix].activate); |
| 186 | 188 | |
| 187 | - widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); | |
| 189 | + accelerators = g_slist_prepend(accelerators,accelerator); | |
| 188 | 190 | |
| 189 | 191 | } |
| 190 | 192 | } |
| ... | ... | @@ -192,6 +194,7 @@ |
| 192 | 194 | } |
| 193 | 195 | |
| 194 | 196 | // Create PF-Key accelerators |
| 197 | + /* | |
| 195 | 198 | { |
| 196 | 199 | static const struct |
| 197 | 200 | { |
| ... | ... | @@ -236,8 +239,9 @@ |
| 236 | 239 | } |
| 237 | 240 | |
| 238 | 241 | } |
| 242 | + */ | |
| 239 | 243 | |
| 240 | - v3270_accelerator_map_sort(widget); | |
| 244 | + return v3270_accelerator_map_sort(accelerators); | |
| 241 | 245 | |
| 242 | 246 | } |
| 243 | 247 | ... | ... |
src/terminal/keyboard/keyfile.c
| ... | ... | @@ -44,36 +44,18 @@ |
| 44 | 44 | static void save_accelerator(const V3270Accelerator * accel, const char *keys, gpointer ptr) |
| 45 | 45 | { |
| 46 | 46 | |
| 47 | - if(accel->type == V3270_ACCELERATOR_TYPE_PFKEY) | |
| 48 | - { | |
| 49 | - // It's a PF-Key action! | |
| 50 | - g_autofree gchar * key = g_strdup_printf("pf%u",((V3270PFKeyAccelerator *)accel)->keycode); | |
| 51 | - | |
| 52 | - debug("%p %s=%s",accel,v3270_accelerator_get_name(accel),key); | |
| 53 | - | |
| 54 | - g_key_file_set_string( | |
| 55 | - ((struct Args *) ptr)->key_file, | |
| 56 | - ((struct Args *) ptr)->group_name, | |
| 57 | - v3270_accelerator_get_name(accel), | |
| 58 | - key | |
| 59 | - ); | |
| 60 | - | |
| 61 | - } | |
| 62 | - else | |
| 63 | - { | |
| 64 | - const gchar * key = v3270_accelerator_get_name(accel); | |
| 65 | - if(!key) | |
| 66 | - return; | |
| 47 | + const gchar * key = v3270_accelerator_get_name(accel); | |
| 48 | + if(!key) | |
| 49 | + return; | |
| 67 | 50 | |
| 68 | 51 | // debug("%s=%s",v3270_accelerator_get_name(accel),keys); |
| 69 | 52 | |
| 70 | - g_key_file_set_string( | |
| 71 | - ((struct Args *) ptr)->key_file, | |
| 72 | - ((struct Args *) ptr)->group_name, | |
| 73 | - key, | |
| 74 | - (keys ? keys : "") | |
| 75 | - ); | |
| 76 | - } | |
| 53 | + g_key_file_set_string( | |
| 54 | + ((struct Args *) ptr)->key_file, | |
| 55 | + ((struct Args *) ptr)->group_name, | |
| 56 | + key, | |
| 57 | + (keys ? keys : "") | |
| 58 | + ); | |
| 77 | 59 | |
| 78 | 60 | } |
| 79 | 61 | |
| ... | ... | @@ -137,36 +119,11 @@ |
| 137 | 119 | for(ix=0;keycodes[ix];ix++) |
| 138 | 120 | { |
| 139 | 121 | |
| 140 | - if(accel->type == V3270_ACCELERATOR_TYPE_PFKEY) | |
| 141 | - { | |
| 142 | - // It's a PFKey redirector | |
| 143 | - | |
| 144 | - unsigned int pfkey = 0; | |
| 145 | - | |
| 146 | - if(sscanf(keycodes[ix],"pf%u",&pfkey) != 1) | |
| 147 | - { | |
| 148 | - g_warning("Can't parse key \"%s\" for accelerator %s",keycodes[ix],v3270_accelerator_get_name(accel)); | |
| 149 | - return; | |
| 150 | - } | |
| 151 | - | |
| 152 | - debug("Creating special accelerator %s",v3270_accelerator_get_name(accel)); | |
| 153 | - | |
| 154 | - // Remap PFKey accelerator | |
| 155 | - V3270Accelerator * acc = v3270_accelerator_clone(accel); | |
| 156 | - ((V3270PFKeyAccelerator *) acc)->keycode = (unsigned short) pfkey; | |
| 157 | - terminal->accelerators = g_slist_prepend(terminal->accelerators,acc); | |
| 158 | - | |
| 159 | - debug("****[%s]***",v3270_accelerator_get_name(accel)); | |
| 160 | - | |
| 161 | - } | |
| 162 | - else | |
| 163 | - { | |
| 164 | - // Standard accelerator. | |
| 165 | - V3270Accelerator * acc = v3270_accelerator_clone(accel); | |
| 166 | - gtk_accelerator_parse(keycodes[ix],&acc->key,&acc->mods); | |
| 167 | - acc->key = gdk_keyval_to_lower(acc->key); | |
| 168 | - terminal->accelerators = g_slist_prepend(terminal->accelerators,acc); | |
| 169 | - } | |
| 122 | + // Standard accelerator. | |
| 123 | + V3270Accelerator * acc = v3270_accelerator_clone(accel); | |
| 124 | + gtk_accelerator_parse(keycodes[ix],&acc->key,&acc->mods); | |
| 125 | + acc->key = gdk_keyval_to_lower(acc->key); | |
| 126 | + terminal->accelerators = g_slist_prepend(terminal->accelerators,acc); | |
| 170 | 127 | |
| 171 | 128 | } |
| 172 | 129 | |
| ... | ... | @@ -205,7 +162,7 @@ |
| 205 | 162 | |
| 206 | 163 | g_strfreev(keys); |
| 207 | 164 | |
| 208 | - v3270_accelerator_map_sort(terminal); | |
| 165 | + terminal->accelerators = v3270_accelerator_map_sort(terminal->accelerators); | |
| 209 | 166 | |
| 210 | 167 | g_object_thaw_notify(G_OBJECT(widget)); |
| 211 | 168 | terminal->freeze = 0; | ... | ... |
src/terminal/keyboard/map.c
| ... | ... | @@ -44,7 +44,8 @@ |
| 44 | 44 | g_slist_free_full(terminal->accelerators,g_free); |
| 45 | 45 | terminal->accelerators = NULL; |
| 46 | 46 | } |
| 47 | - v3270_init_accelerators(terminal); | |
| 47 | + terminal->accelerators = v3270_accelerator_map_load_default(NULL); | |
| 48 | + | |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | 51 | } |
| ... | ... | @@ -57,9 +58,9 @@ |
| 57 | 58 | return a->arg - b->arg; |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | - void v3270_accelerator_map_sort(v3270 *widget) | |
| 61 | + GSList * v3270_accelerator_map_sort(GSList * accelerators) | |
| 61 | 62 | { |
| 62 | - widget->accelerators = g_slist_sort(widget->accelerators, (GCompareFunc) compare_func); | |
| 63 | + return g_slist_sort(accelerators, (GCompareFunc) compare_func); | |
| 63 | 64 | } |
| 64 | 65 | |
| 65 | 66 | void v3270_accelerator_map_foreach(GtkWidget *widget,void (*call)(const V3270Accelerator * accel, const char *keys, gpointer ptr), gpointer ptr) | ... | ... |
src/terminal/widget.c
| ... | ... | @@ -565,13 +565,8 @@ static void v3270_init(v3270 *widget) |
| 565 | 565 | v3270_font_info_init(&widget->font); |
| 566 | 566 | v3270_set_color_table(widget->color,v3270_get_default_colors()); |
| 567 | 567 | |
| 568 | - /* | |
| 569 | - for(ix = 0; ix < G_N_ELEMENTS(widget->responses); ix++) | |
| 570 | - widget->responses[ix] = GTK_RESPONSE_NONE; | |
| 571 | - */ | |
| 572 | - | |
| 573 | 568 | // Init accelerators |
| 574 | - v3270_init_accelerators(widget); | |
| 569 | + widget->accelerators = v3270_accelerator_map_load_default(NULL); | |
| 575 | 570 | |
| 576 | 571 | } |
| 577 | 572 | ... | ... |