void move_win_pho(int x, int y) { int twin_xl, twin_yl; win_x = x; win_y = y; if (!gwin_pho) return; get_win_size(gwin_pho, &twin_xl, &twin_yl); if (x + twin_xl > dpy_xl) x = dpy_xl - twin_xl; if (x < 0) x = 0; if (y + twin_yl > dpy_yl) y = dpy_yl - twin_yl; if (y < 0) y = 0; gtk_window_move(GTK_WINDOW(gwin_pho), x, y); move_win_sym(); }
int get_widget_xy(GtkWidget *win, GtkWidget *widget, int *rx, int *ry) { if (!win && !widget) p_err("get_widget_xy err"); // gdk_flush(); GtkRequisition sz; gtk_widget_get_preferred_size(widget, NULL, &sz); int wx, wy; wx=wy=0; gtk_widget_translate_coordinates(widget, win, 0, sz.height, &wx, &wy); gtk_widget_translate_coordinates(widget, win, 0, sz.height, &wx, &wy); // dbg("%d wx:%d\n", index, wx); int win_x, win_y; gtk_window_get_position(GTK_WINDOW(win), &win_x, &win_y); int win_xl, win_yl; get_win_size(win, &win_xl, &win_yl); if (wx > win_xl) wx = win_xl; *rx = win_x + wx; *ry = win_y + wy; return wx; }
void get_win0_geom() { if (!gwin0) return; gtk_window_get_position(GTK_WINDOW(gwin0), &win_x, &win_y); get_win_size(gwin0, &win_xl, &win_yl); }
gboolean win_size_exceed(GtkWidget *win) { int width, height; get_win_size(win, &width, &height); return (width + current_in_win_x > dpy_xl || height + current_in_win_y > dpy_yl); }
void disp_win_screen_status(char *in_method, char *half_status) { dbg("disp_win_screen_status\n"); if ( // tss.c_len || ggg.gbufN || cur_file_hf && !strcmp(cur_file_hf, half_status) && cur_file_inmd && !strcmp(cur_file_inmd, in_method) #if 0 && old_x==current_in_win_x && old_y==current_in_win_y #endif ) return; old_x = current_in_win_x; old_y = current_in_win_y; clear_timeout(); free(cur_file_hf); cur_file_hf = strdup(half_status); free(cur_file_inmd); cur_file_inmd = strdup(in_method); if (!win_screen_status) { win_screen_status = create_no_focus_win(); GtkWidget *hbox = gtk_hbox_new (FALSE, 0); gtk_container_add(GTK_CONTAINER(win_screen_status), hbox); icon_inmd = gtk_image_new_from_file(in_method); gtk_box_pack_start (GTK_BOX (hbox), icon_inmd, FALSE, FALSE, 0); #if 1 icon_hf = gtk_image_new_from_file(half_status); gtk_box_pack_start (GTK_BOX (hbox), icon_hf, FALSE, FALSE, 0); #endif } else { #if 1 gtk_image_set_from_file(GTK_IMAGE(icon_hf), half_status); #endif gtk_image_set_from_file(GTK_IMAGE(icon_inmd), in_method); } gtk_widget_show_all(win_screen_status); gtk_window_present(GTK_WINDOW(win_screen_status)); timeout_handle = g_timeout_add(1000, timeout_hide, NULL); int w,h; get_win_size(win_screen_status, &w, &h); int x = current_in_win_x; int y = current_in_win_y + (win_is_visible()?win_yl:0); if (x + w > dpy_xl) x = dpy_xl - w; if (y + h > dpy_yl) y = win_y - h; gtk_window_move(GTK_WINDOW(win_screen_status), x, y); }
void disp_selections(int x, int y) { if (!gwin1) p_err("disp_selections !gwin1"); if (y < 0) { int tx; if (gcin_edit_display_ap_only()) getRootXY(current_CS->client_win, current_CS->spot_location.x, current_CS->spot_location.y, &tx, &y); else y = win_y + win_yl; } int win1_xl, win1_yl; get_win_size(gwin1, &win1_xl, &win1_yl); if (x < 0) { x = win_x + win_xl - win1_xl; if (x < win_x) x = win_x; } if (x + win1_xl > dpy_xl) x = dpy_xl - win1_xl; if (y + win1_yl > dpy_yl) y = win_y - win1_yl; if (y < 0) y = 0; gtk_window_move(GTK_WINDOW(gwin1), x, y); #if WIN32 && 1 if (!GTK_WIDGET_VISIBLE(gwin1)) { gtk_widget_show(gwin1); } #endif #if WIN32 && 1 #if 0 if (!timeout_handle) timeout_handle = g_timeout_add(100, timeout_minimize_win1, NULL); #endif set_win_pos_size(gwin1, x, y, win1_xl, win1_yl); gtk_window_present(GTK_WINDOW(gwin1)); #endif #if UNIX || 0 if (!GTK_WIDGET_VISIBLE(gwin1)) { gtk_widget_show(gwin1); } #endif }
static void move_win_kbm() { int width, height; get_win_size(gwin_kbm, &width, &height); int ox, oy; GdkRectangle r; GtkOrientation ori; #if UNIX int szx, szy; if (tray_da_win) { gdk_window_get_origin(tray_da_win, &ox, &oy); #if !GTK_CHECK_VERSION(2,91,0) gdk_drawable_get_size(tray_da_win, &szx, &szy); #else szx = gdk_window_get_width(tray_da_win); szy = gdk_window_get_height(tray_da_win); #endif if (oy<height) { oy = szy; } else { oy -= height; if (oy + height > dpy_yl) oy = dpy_yl - height; if (oy < 0) oy = szy; } if (ox + width > dpy_xl) ox = dpy_xl - width; if (ox < 0) ox = 0; } else #endif if (icon_main && gtk_status_icon_get_geometry(icon_main, NULL, &r, &ori)) { // dbg("rect %d:%d %d:%d\n", r.x, r.y, r.width, r.height); ox = r.x; if (ox + width > dpy_xl) ox = dpy_xl - width; if (r.y < 100) oy=r.y+r.height; else { oy = r.y - height; } } else { ox = dpy_xl - width; oy = dpy_yl - height - 31; } gtk_window_move(GTK_WINDOW(gwin_kbm), ox, oy); }
static void set_window_size(int rows, int cols, int fd, const char *device_name) { struct winsize win; if (get_win_size(fd, &win)) { if (errno != EINVAL) perror_msg_and_die("%s", device_name); memset(&win, 0, sizeof(win)); } if (rows >= 0) win.ws_row = rows; if (cols >= 0) win.ws_col = cols; # ifdef TIOCSSIZE #if !((MACRO_KERNEL_VERSION == 2) && (MACRO_KERNEL_PATCHLEVEL == 0) && defined(__sparc__)) /* Alexander Dupuy <*****@*****.**> wrote: The following code deals with a bug in the SunOS 4.x (and 3.x?) kernel. This comment from sys/ttold.h describes Sun's twisted logic - a better test would have been (ts_lines > 64k || ts_cols > 64k || ts_cols == 0). At any rate, the problem is gone in Solaris 2.x. */ if (win.ws_row == 0 || win.ws_col == 0) { struct ttysize ttysz; ttysz.ts_lines = win.ws_row; ttysz.ts_cols = win.ws_col; win.ws_row = 1; win.ws_col = 1; if (ioctl(fd, TIOCSWINSZ, (char *) &win)) perror_msg_and_die("%s", device_name); if (ioctl(fd, TIOCSSIZE, (char *) &ttysz)) perror_msg_and_die("%s", device_name); return; } # endif # endif if (ioctl(fd, TIOCSWINSZ, (char *) &win)) perror_msg_and_die("%s", device_name); }
int show_window( void ) { clear_screen(); get_win_size( &winx, &winy ); rectangle( 1, 1, winx, winy ); move_xy( 3, 3 ); printf("善哉词霸"); rectangle( 13, 2, winx-15, 3 ); line( 1, 5, winx, 0, '=' ); line( winx / 3, 6, winy-6, 1, '|' ); move_xy( 10,10 ); fflush( NULL ); }
static void display_window_size(int fancy, int fd, const char *device_name) { struct winsize win; if (get_win_size(fd, &win)) { if (errno != EINVAL) perror_msg_and_die("%s", device_name); if (!fancy) perror_msg_and_die("%s: no size information for this device", device_name); } else { wrapf(fancy ? "rows %d; columns %d;" : "%d %d\n", win.ws_row, win.ws_col); if (!fancy) current_col = 0; } }
static void raw_move(int x, int y) { int xl, yl; if (!gwin0) return; get_win_size(gwin0, &xl, &yl); if (x + xl > dpy_xl) x = dpy_xl - xl; if (y + yl > dpy_yl) y = dpy_yl - yl; gtk_window_move(GTK_WINDOW(gwin0), x, y); // dbg("gwin0:%x raw_move %d,%d\n", gwin0, x, y); }
void show_elems() { int i; int x; int y; int max; char space = 5; get_win_size(); gl_env.flag = 0; term_clear(); //my_int(gl_env.nbelems); for(i=0, x=0, y=0, max=0; i<gl_env.nbelems; i++, y++) { //my_int(gl_env.win.ws_row); if(y>= gl_env.win.ws_row) { x+=(max+ space); y=0; max=0; } if(max <gl_env.elements[i].size) max = gl_env.elements[i].size; if((x+max) >= gl_env.win.ws_col) { term_clear(); gl_env.flag = 1; term_move(0,0); my_str("Please Enlarge Window"); break; } gl_env.elements[i].x = x; gl_env.elements[i].y = y; //my_int(max); refresh_out(i); //my_int(max); } if(!gl_env.flag) refresh_in(); }
void move_win_sym() { #if 0 dbg("move_win_sym %d\n", current_CS->in_method); #endif if (!gwin_sym) return; int wx, wy; #if 0 if (gcin_pop_up_win) { wx = dpy_xl; } else #endif { // dbg("win_y: %d %d\n", win_y, win_yl); update_active_in_win_geom(); wx = win_x; wy = win_y + win_yl; } int winsym_xl, winsym_yl; get_win_size(gwin_sym, &winsym_xl, &winsym_yl); if (wx + winsym_xl > dpy_xl) wx = dpy_xl - winsym_xl; if (wx < 0) wx = 0; #if 0 if (gcin_pop_up_win) { wy = win_status_y - winsym_yl; } else #endif { if (wy + winsym_yl > dpy_yl) wy = win_y - winsym_yl; if (wy < 0) wy = 0; } gtk_window_move(GTK_WINDOW(gwin_sym), wx, wy); }
static int screen_columns(void) { #ifdef TIOCGWINSZ struct winsize win; /* With Solaris 2.[123], this ioctl fails and errno is set to EINVAL for telnet (but not rlogin) sessions. On ISC 3.0, it fails for the console and the serial port (but it works for ptys). It can also fail on any system when stdout isn't a tty. In case of any failure, just use the default. */ if (get_win_size(STDOUT_FILENO, &win) == 0 && win.ws_col > 0) return win.ws_col; #endif if (getenv("COLUMNS")) return atoi(getenv("COLUMNS")); return 80; }
void init_terminal() { char* name; int fd; struct termios ts; name = ttyname(0); fd = open(name, O_WRONLY); gl_env.stdio_backup = dup(1); dup2(fd, 1); //my_str("setting up terminal\n"); if(tcgetattr(fd, &(gl_env.line_backup)) < 0) { my_str("Error: linebakup"); exit(1); } ts = gl_env.line_backup; ts.c_lflag &= ~(ICANON | ECHO | ISIG); ts.c_cc[VTIME] = 1; ts.c_cc[VMIN] = 3; if(tcsetattr(fd, TCSAFLUSH, &ts) < 0) { my_str("Error with tcsetattr"); exit(1); } get_win_size(); //setbuff(1, NULL); //my_int(gl_env.win.ws_col); //my_int(gl_env.win.ws_row); //my_str("Finished terminal set up\n"); }
void move_win_gtab(int x, int y) { if (!gwin_gtab) return; // dbg("move_win_gtab %d %d\n", x, y); get_win_size(gwin_gtab, &win_xl, &win_yl); if (x + win_xl > dpy_xl) x = dpy_xl - win_xl; if (x < 0) x = 0; if (y + win_yl > dpy_yl) y = dpy_yl - win_yl; if (y < 0) y = 0; gtk_window_move(GTK_WINDOW(gwin_gtab), x, y); win_x = x; win_y = y; move_win_sym(); if (poo.same_pho_query_state != SAME_PHO_QUERY_none) move_gtab_pho_query_win(); }
/* Recursive help */ tvalue gen_cli_print_help(char *prog_name,gen_cli_argument *arg) { unsigned int arglen; unsigned int rows,cols; char *format_mand=" <%s>",*format_opt=" [%s]"; char *cmd_fmt=format_mand,*flag_fmt=format_mand; ARG_ASSERT(!prog_name || !arg,FALSE); print_out("\nUsage: "); if(arg->cmd != NULL) print_command_path(prog_name,arg); else print_out("%s",prog_name); if(arg->helpcmdparameter != NULL) print_out(" %s",arg->helpcmdparameter); /* check if commands or flags are optional */ if(arg->flags & GEN_CLI_CMDS_OPTIONAL) cmd_fmt=format_opt; if(arg->flags & GEN_CLI_FLAGS_OPTIONAL) flag_fmt=format_opt; if(arg->subcmds) print_out(cmd_fmt,"command"); if(arg->opt.options != NULL) print_out(flag_fmt,"options"); if(arg->helpcmdextra != NULL) print_out(" %s",arg->helpcmdextra); print_out("\n\n"); get_win_size(&rows,&cols); print_explain(0,arg->cmdhelp,cols); print_out("\n\n"); arglen = getprintpos(arg); /* print short descriptions of the subcommands */ if(arg->subcmds) { register unsigned int beta,gamma; unsigned int curlen=0; /* if(arg->cmd != NULL) print_out("Subc"); else print_out("C"); */ print_out("%sommands:\n", (arg->cmd) ? "Subc" : "C"); for(beta=0;arg->subcmds[beta];beta++) { curlen=PRINTSPACELEN + strlen(arg->subcmds[beta]->cmd); print_out(PRINTSPACE "%s",arg->subcmds[beta]->cmd); if(arg->subcmds[beta]->shortcmd != 0) print_out(" (%c)",arg->subcmds[beta]->shortcmd); for(gamma = curlen; gamma < arglen; gamma++) print_out(" "); print_explain(arglen-1,arg->subcmds[beta]->cmdhelp,cols); } print_out("\n"); } /* print out the flags */ if(arg->opt.options) { print_out("Options:\n"); print_flags(arg->opt.options,arg->opt.help_strs,arglen,cols); } return TRUE; }
static void create_win_message(char *icon, char *text, int duration) { GtkWidget *gwin_message = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip(GTK_WINDOW(gwin_message), FALSE); gtk_container_set_border_width (GTK_CONTAINER (gwin_message), 0); gtk_widget_realize (gwin_message); GdkWindow *gdkwin = gtk_widget_get_window(gwin_message); set_no_focus(gwin_message); GtkWidget *hbox = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (gwin_message), hbox); if (icon[0] != '-') { GtkWidget *image = gtk_image_new_from_file(icon); if (text[0] == '-') { #if GTK_CHECK_VERSION(2,91,0) GdkPixbuf *pixbuf = NULL; GdkPixbufAnimation *anime = NULL; switch(gtk_image_get_storage_type(GTK_IMAGE(image))) { case GTK_IMAGE_PIXBUF: pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); break; case GTK_IMAGE_ANIMATION: anime = gtk_image_get_animation(GTK_IMAGE(image)); pixbuf = gdk_pixbuf_animation_get_static_image(anime); break; default: break; } cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); cairo_t *cr = cairo_create(img); gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); cairo_paint(cr); cairo_region_t *mask = gdk_cairo_region_create_from_surface(img); gtk_widget_shape_combine_region(gwin_message, mask); cairo_region_destroy(mask); cairo_destroy(cr); cairo_surface_destroy(img); #else GdkBitmap *bitmap = NULL; gdk_pixbuf_render_pixmap_and_mask(gdk_pixbuf_new_from_file(icon, NULL), NULL, &bitmap, 128); gtk_widget_shape_combine_mask(gwin_message, bitmap, 0, 0); #endif } gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); } if (text[0] != '-') { GtkWidget *label = gtk_label_new(text); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); } gtk_widget_show_all(gwin_message); int width, height; get_win_size(gwin_message, &width, &height); int ox=-1, oy; int szx, szy; if (tray_da_win) { gdk_window_get_origin (tray_da_win, &ox, &oy); #if !GTK_CHECK_VERSION(2,91,0) gdk_drawable_get_size(tray_da_win, &szx, &szy); #else szx = gdk_window_get_width(tray_da_win); szy = gdk_window_get_height(tray_da_win); #endif if (oy<height) { oy = szy; } else { oy -= height; if (oy + height > dpy_yl) oy = dpy_yl - height; if (oy < 0) oy = 0; } if (ox + width > dpy_xl) ox = dpy_xl - width; if (ox < 0) ox = 0; } else if (icon_main) { GdkRectangle rect; GtkOrientation ori; if (gtk_status_icon_get_geometry(icon_main, NULL, &rect, &ori)) { dbg("rect %d,%d\n", rect.x, rect.y, rect.width, rect.height); if (ori==GTK_ORIENTATION_HORIZONTAL) { ox=rect.x; if (rect.y > 100) oy=rect.y - height; else oy=rect.y + rect.height; } else { oy=rect.y; if (rect.x > 100) ox=rect.x - width; else ox=rect.x + rect.width; } } } if (ox < 0) { ox = dpy_xl - width; oy = dpy_yl - height; } gtk_window_move(GTK_WINDOW(gwin_message), ox, oy); g_timeout_add(duration, (GSourceFunc)timeout_destroy_window, gwin_message); }