⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 linux下很好的截图工具。 抓取整个桌面、某个指定的窗口、以及选择的矩形区域。
💻 C
📖 第 1 页 / 共 2 页
字号:
      int stat;      /* else it's a window click */      /* get geometry of window and use that */      /* get windowmanager frame of window */      if (target != root) {        unsigned int d, x;        int status;        status = XGetGeometry(disp, target, &root, &x, &x, &d, &d, &d, &d);        if (status != 0) {          Window rt, *children, parent;          for (;;) {            /* Find window manager frame. */            status = XQueryTree(disp, target, &rt, &parent, &children, &d);            if (status && (children != None))              XFree((char *) children);            if (!status || (parent == None) || (parent == rt))              break;            target = parent;          }          /* Get client window. */          if (!opt.border)            target = scrot_get_client_window(disp, target);          XRaiseWindow(disp, target);        }      }      stat = XGetWindowAttributes(disp, target, &attr);      if ((stat == False) || (attr.map_state != IsViewable))        return NULL;      rw = attr.width;      rh = attr.height;      XTranslateCoordinates(disp, target, root, 0, 0, &rx, &ry, &child);    }    /* clip rectangle nicely */    if (rx < 0) {      rw += rx;      rx = 0;    }    if (ry < 0) {      rh += ry;      ry = 0;    }    if ((rx + rw) > scr->width)      rw = scr->width - rx;    if ((ry + rh) > scr->height)      rh = scr->height - ry;    XBell(disp, 0);    im = gib_imlib_create_image_from_drawable(root, 0, rx, ry, rw, rh, 1);  }  return im;}Windowscrot_get_window(Display * display,                 Window window,                 int x,                 int y){  Window source, target;  int status, x_offset, y_offset;  source = root;  target = window;  if (window == None)    window = root;  while (1) {    status =      XTranslateCoordinates(display, source, window, x, y, &x_offset,                            &y_offset, &target);    if (status != True)      break;    if (target == None)      break;    source = window;    window = target;    x = x_offset;    y = y_offset;  }  if (target == None)    target = window;  return (target);}char *im_printf(char *str, struct tm *tm,          char *filename_im,          char *filename_thumb,          Imlib_Image im){  char *c;  char buf[20];  char ret[4096];  char strf[4096];  char *tmp;  struct stat st;  ret[0] = '\0';  strftime(strf, 4095, str, tm);  for (c = strf; *c != '\0'; c++) {    if (*c == '$') {      c++;      switch (*c) {        case 'f':          if (filename_im)            strcat(ret, filename_im);          break;        case 'm': /* t was allready taken, so m as in mini */          if (filename_thumb)            strcat(ret, filename_thumb);          break;        case 'n':          if (filename_im) {            tmp = strrchr(filename_im, '/');            if (tmp)              strcat(ret, tmp + 1);            else              strcat(ret, filename_im);          }          break;        case 'w':          snprintf(buf, sizeof(buf), "%d", gib_imlib_image_get_width(im));          strcat(ret, buf);          break;        case 'h':          snprintf(buf, sizeof(buf), "%d", gib_imlib_image_get_height(im));          strcat(ret, buf);          break;        case 's':          if (filename_im) {            if (!stat(filename_im, &st)) {              int size;              size = st.st_size;              snprintf(buf, sizeof(buf), "%d", size);              strcat(ret, buf);            } else              strcat(ret, "[err]");          }          break;        case 'p':          snprintf(buf, sizeof(buf), "%d",                   gib_imlib_image_get_width(im) *                   gib_imlib_image_get_height(im));          strcat(ret, buf);          break;        case 't':          strcat(ret, gib_imlib_image_format(im));          break;        case '$':          strcat(ret, "$");          break;        default:          strncat(ret, c, 1);          break;      }    } else if (*c == '\\') {      c++;      switch (*c) {        case 'n':          if (filename_im)            strcat(ret, "\n");          break;        default:          strncat(ret, c, 1);          break;      }    } else      strncat(ret, c, 1);  }  return gib_estrdup(ret);}Windowscrot_get_client_window(Display * display,                        Window target){  Atom state;  Atom type = None;  int format, status;  unsigned char *data;  unsigned long after, items;  Window client;  state = XInternAtom(display, "WM_STATE", True);  if (state == None)    return target;  status =    XGetWindowProperty(display, target, state, 0L, 0L, False,                       (Atom) AnyPropertyType, &type, &format, &items, &after,                       &data);  if ((status == Success) && (type != None))    return target;  client = scrot_find_window_by_property(display, target, state);  if (!client)    return target;  return client;}Windowscrot_find_window_by_property(Display * display,                              const Window window,                              const Atom property){  Atom type = None;  int format, status;  unsigned char *data;  unsigned int i, number_children;  unsigned long after, number_items;  Window child = None, *children, parent, root;  status =    XQueryTree(display, window, &root, &parent, &children, &number_children);  if (!status)    return None;  for (i = 0; (i < number_children) && (child == None); i++) {    status =      XGetWindowProperty(display, children[i], property, 0L, 0L, False,                         (Atom) AnyPropertyType, &type, &format,                         &number_items, &after, &data);    if (data)      XFree(data);    if ((status == Success) && (type != (Atom) NULL))      child = children[i];  }  for (i = 0; (i < number_children) && (child == None); i++)    child = scrot_find_window_by_property(display, children[i], property);  if (children != None)    XFree(children);  return (child);}Imlib_Imagescrot_grab_shot_multi(void){  int screens;  int i;  char *dispstr, *subdisp;  char newdisp[255];  gib_list *images = NULL;  Imlib_Image ret = NULL;  screens = ScreenCount(disp);  if (screens < 2)    return scrot_grab_shot();  dispstr = DisplayString(disp);  subdisp = gib_estrdup(DisplayString(disp));  for (i = 0; i < screens; i++) {    dispstr = strchr(subdisp, ':');    if (dispstr) {      dispstr = strchr(dispstr, '.');      if (NULL != dispstr)        *dispstr = '\0';    }    snprintf(newdisp, sizeof(newdisp), "%s.%d", subdisp, i);    init_x_and_imlib(newdisp, i);    ret =      gib_imlib_create_image_from_drawable(root, 0, 0, 0, scr->width,                                           scr->height, 1);    images = gib_list_add_end(images, ret);  }  free(subdisp);  ret = stalk_image_concat(images);  return ret;}Imlib_Imagestalk_image_concat(gib_list * images){  int tot_w = 0, max_h = 0, w, h;  int x = 0;  gib_list *l, *item;  Imlib_Image ret, im;  if (gib_list_length(images) == 0)    return NULL;  l = images;  while (l) {    im = (Imlib_Image) l->data;    h = gib_imlib_image_get_height(im);    w = gib_imlib_image_get_width(im);    if (h > max_h)      max_h = h;    tot_w += w;    l = l->next;  }  ret = imlib_create_image(tot_w, max_h);  gib_imlib_image_fill_rectangle(ret, 0, 0, tot_w, max_h, 255, 0, 0, 0);  l = images;  while (l) {    im = (Imlib_Image) l->data;    item = l;    l = l->next;    h = gib_imlib_image_get_height(im);    w = gib_imlib_image_get_width(im);    gib_imlib_blend_image_onto_image(ret, im, 0, 0, 0, w, h, x, 0, w, h, 1, 0,                                     0);    x += w;    gib_imlib_free_image_and_decache(im);    free(item);  }  return ret;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -