void save_remote_modifiers(uint8 scancode) { if (is_modifier(scancode)) return; saved_remote_modifier_state = remote_modifier_state; }
void key_release(int key) { if (is_modifier(key)) report_modifier_remove(key); else if (is_printable(key)) report_key_remove(asciimap[key]); else report_key_remove(key); }
void key_press(int key) { if (is_modifier(key)) report_modifier_add(key); else if (is_printable(key)) report_key_add(asciimap[key]); else report_key_add(key); }
void restore_remote_modifiers(uint32 ev_time, uint8 scancode) { key_translation dummy = { }; if (is_modifier(scancode)) return; dummy.scancode = 0; dummy.modifiers = saved_remote_modifier_state; ensure_remote_modifiers(ev_time, dummy); }
void ensure_remote_modifiers(uint32 ev_time, key_translation tr) { /* If this key is a modifier, do nothing */ if (is_modifier(tr.scancode)) return; if (!g_numlock_sync) { /* NumLock */ if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) { /* The remote modifier state is not correct */ uint16 new_remote_state; if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) { DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); new_remote_state = KBD_FLAG_NUMLOCK; remote_modifier_state = MapNumLockMask; } else { DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); new_remote_state = 0; remote_modifier_state = 0; } rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); } } /* Shift. Left shift and right shift are treated as equal; either is fine. */ if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) != MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) { /* The remote modifier state is not correct */ if (MASK_HAS_BITS(tr.modifiers, MapLeftShiftMask)) { /* Needs left shift. Send down. */ rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); } else if (MASK_HAS_BITS(tr.modifiers, MapRightShiftMask)) { /* Needs right shift. Send down. */ rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RSHIFT); } else { /* Should not use this modifier. Send up for shift currently pressed. */ if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask)) /* Left shift is down */ rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); else /* Right shift is down */ rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); } } /* AltGr */ if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask) != MASK_HAS_BITS(remote_modifier_state, MapAltGrMask)) { /* The remote modifier state is not correct */ if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)) { /* Needs this modifier. Send down. */ rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RALT); } else { /* Should not use this modifier. Send up. */ rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); } } }
static gboolean grab_key_callback(GtkWidget* widget, GdkEventKey* event, void* data) { GdkModifierType accel_mods = 0; guint accel_keyval; EggCellRendererKeys *keys; char *path; gboolean edited; gboolean cleared; GdkModifierType consumed_modifiers; guint upper; GdkModifierType ignored_modifiers; keys = EGG_CELL_RENDERER_KEYS(data); if (is_modifier(event->hardware_keycode)) { return TRUE; } edited = FALSE; cleared = FALSE; consumed_modifiers = 0; gdk_keymap_translate_keyboard_state(gdk_keymap_get_default(), event->hardware_keycode, event->state, event->group, NULL, NULL, NULL, &consumed_modifiers); upper = event->keyval; accel_keyval = gdk_keyval_to_lower(upper); if (accel_keyval == GDK_ISO_Left_Tab) { accel_keyval = GDK_Tab; } /* Put shift back if it changed the case of the key, not otherwise. */ if (upper != accel_keyval && (consumed_modifiers & GDK_SHIFT_MASK)) { consumed_modifiers &= ~(GDK_SHIFT_MASK); } egg_keymap_resolve_virtual_modifiers(gdk_keymap_get_default(), EGG_VIRTUAL_NUM_LOCK_MASK | EGG_VIRTUAL_SCROLL_LOCK_MASK | EGG_VIRTUAL_LOCK_MASK, &ignored_modifiers); /* http://bugzilla.gnome.org/show_bug.cgi?id=139605 * mouse keys should effect keybindings */ ignored_modifiers |= GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | GDK_BUTTON5_MASK; /* filter consumed/ignored modifiers */ if (keys->accel_mode == EGG_CELL_RENDERER_KEYS_MODE_GTK) { accel_mods = event->state & GDK_MODIFIER_MASK & ~(consumed_modifiers | ignored_modifiers); } else if (keys->accel_mode == EGG_CELL_RENDERER_KEYS_MODE_X) { accel_mods = event->state & GDK_MODIFIER_MASK & ~(ignored_modifiers); } else { g_assert_not_reached(); } if (accel_mods == 0 && accel_keyval == GDK_Escape) { goto out; /* cancel */ } /* clear the accelerator on Backspace */ if (accel_mods == 0 && accel_keyval == GDK_BackSpace) { cleared = TRUE; goto out; } if (keys->accel_mode == EGG_CELL_RENDERER_KEYS_MODE_GTK) { if (!gtk_accelerator_valid (accel_keyval, accel_mods)) { accel_keyval = 0; accel_mods = 0; } } edited = TRUE; out: gdk_keyboard_ungrab(event->time); gdk_pointer_ungrab(event->time); path = g_strdup(g_object_get_data(G_OBJECT(keys->edit_widget), EGG_CELL_RENDERER_TEXT_PATH)); gtk_cell_editable_editing_done(GTK_CELL_EDITABLE(keys->edit_widget)); gtk_cell_editable_remove_widget(GTK_CELL_EDITABLE(keys->edit_widget)); keys->edit_widget = NULL; keys->grab_widget = NULL; if (edited) { g_signal_emit_by_name(G_OBJECT(keys), "accel_edited", path, accel_keyval, accel_mods, event->hardware_keycode); } else if (cleared) { g_signal_emit_by_name(G_OBJECT(keys), "accel_cleared", path); } g_free (path); return TRUE; }
void read_file(char *filename,struct Process **pproc) { FILE *fp; char *endfile,line[MAXSTR],*p,save_token[MAXSTR]; int label_bool=0,line_count=0,num_code=0,n_args; struct instruction_node *new_instr; struct Process *proc; struct expr_node *new_expr; proc=(struct Process*)malloc(sizeof(struct Process)); if(proc==NULL) die("errore nell'allocare struct Process"); proc->pt=NULL; proc->pc=NULL; proc->prev=NULL; proc->next=NULL; proc->processID=get_processID(); fp=fopen(filename,"r"); if(fp==NULL) die("error opening file"); proc->pc=(struct process_construct*)malloc(sizeof(struct process_construct)); if(proc->pc==NULL) die("errore nell'allocare process_construct"); proc->pc->first=NULL; proc->pc->last=NULL; proc->pc->len=0; proc->pc->org[0]='\0'; proc->pc->vt_first=NULL; proc->pc->vt_last=NULL; while((endfile=fgets(line,MAXSTR,fp))!=NULL) { line_count++; p=&line[0]; if(*p==';') continue; p=skip_space(p); if(*p=='\n') continue; p=get_token(p); p=skip_space(p); if((strcmp(my_token,"org"))==0) { p=get_word(p);strncpy(proc->pc->org,my_token,MAXSTR); if(*p!='\n') {sprintf(save_token,"parse error at line %d. not an end line after the org argument",line_count);die(save_token);} continue; } if((strcmp(my_token,"end"))==0) { p=skip_space(p); if(*p!='\n') {sprintf(save_token,"parse error after 'end' at line %d.",line_count);die(save_token);} break; } if((strcmp(my_token,"assert"))==0) { take_assert(p); new_expr=(struct expr_node*)malloc(sizeof(struct expr_node)); if(new_expr==NULL) {printf("at line %d, ",line_count);die("error allocating new_expr");} p=skip_space(p); p=get_b_arg(&new_expr,p,line_count); insert_in_vt(ASSERT_STR,new_expr,line_count,proc); continue; } if(*p==':') { insert_label(my_token,num_code,line_count,proc);p=skip_space(++p); if(*p=='\n') continue; p=get_token(p); } n_args=is_instr(my_token,line_count); if(n_args!=-1) { new_instr=(struct instruction_node*)malloc(sizeof(struct instruction_node)); if(new_instr==NULL) {printf("at line %d , ",line_count);die("error allocating new_instr");} strncpy(new_instr->instr,my_token,MAXSTR); new_instr->num_node=num_code++; new_instr->line_count=line_count; new_instr->prev=NULL; new_instr->next=NULL; new_instr->code=NULL; new_instr->left=NULL; new_instr->right=NULL; new_instr->laddr[0]='#';new_instr->laddr[1]='\0'; new_instr->raddr[0]='#';new_instr->raddr[1]='\0'; strcpy(new_instr->modifier,"NULL"); if(*p=='.'){ p=get_word(++p);is_modifier(my_token,line_count); strncpy(new_instr->modifier,my_token,MAXMOD); } p=skip_space(p); if(n_args>0) { p=get_addr_mode(p); //$ by default. the result is in my_token new_instr->laddr[0]=my_token[0]; new_instr->laddr[1]='\0'; //p=get_token(p); //new_instr->left=(struct expr_node*)malloc(sizeof(struct expr_node)); //if(new_instr->left==NULL){ //printf("at line %d , ",line_count);die("error alocating left expr");} p=get_arg(&new_instr->left,p,line_count); p=skip_space(p); if(n_args>1) { if(*p!=',') {printf("at line %d , ",line_count);die("a comma expected (,)");} p=skip_space(++p); p=get_addr_mode(p); //$ by default. the result is in my_token new_instr->raddr[0]=my_token[0]; new_instr->raddr[1]='\0'; //p=get_token(p); //new_instr->right=(struct expr_node*)malloc(sizeof(struct expr_node)); //if(new_instr->right==NULL){ //printf("at line %d , ",line_count);die("error allocating right expr");} p=get_arg(&new_instr->right,p,line_count); p=skip_space(p); } } if(*p!='\n') {printf("at line %d , ",line_count);die("not an ending line after command");} //add the node add_node(new_instr,proc); continue; } strncpy(save_token,my_token,MAXSTR); p=get_token(p); if((strcmp(my_token,"equ"))==0) { new_expr=(struct expr_node*)malloc(sizeof(struct expr_node)); if(new_expr==NULL) {printf("at line %d, ",line_count);die("error allocating new_expr");} p=skip_space(p); p=get_arg(&new_expr,p,line_count); insert_in_vt(save_token,new_expr,line_count,proc); continue; } } fclose(fp); proc->pc->len=num_code; add_proc(proc); *pproc=proc; }