Пример #1
0
Файл: bar.c Проект: nqv/nilwm
void update_bar_ws(unsigned int idx) {
    xcb_rectangle_t rect;
    uint32_t vals[2];
    char text[3];
    int len;

    /* colors */
    vals[0] = nil_.color.bar_fg;
    if (idx == nil_.ws_idx) {               /* focused workspace */
        vals[1] = nil_.color.bar_sel;
    } else if (nil_.ws[idx].first) {        /* has a client */
        vals[1] = nil_.color.bar_occ;
    } else {
        vals[1] = nil_.color.bar_bg;
    }
    xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND, &vals[1]);
    rect.width = bar_.box[BAR_WS].w / cfg_.num_workspaces;
    rect.height = bar_.h;
    rect.x = bar_.box[BAR_WS].x + rect.width * idx;
    rect.y = 0;
    xcb_poly_fill_rectangle(nil_.con, bar_.win, bar_.gc, 1, &rect);

    /* text */
    xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, vals);
    len = snprintf(text, sizeof(text), "%u", idx + 1);
    rect.x += CENTER_H_(rect.width, cal_text_width(text, len));
    rect.y += CENTER_V_(rect.height);
    xcb_image_text_8(nil_.con, len, bar_.win, bar_.gc, rect.x, rect.y, text);
}
Пример #2
0
  /** Draws a black background with white text.
      Should be calld when an expose event is received.
  */
  void redraw() {
    // convert the text to be displayed.
    xcb_char2b_t *str = char2b(text);

    // get the dimensions of the text
    xcb_query_text_extents_cookie_t cookie = 
      xcb_query_text_extents(con, font, text.size(), str);
    delete[] str;

    xcb_generic_error_t *error;
    xcb_query_text_extents_reply_t *reply =
      xcb_query_text_extents_reply(con, cookie, &error);
    if(error)
      {
        std::cerr << "Could not query text extents." << std::endl;
        exit(1);
      }

    // draw the text in the middle of the window.
    xcb_image_text_8(con, text.size(), win, txt_gc,
                     width/2 - reply->overall_width/2, height/2, text.c_str());

    free(reply);
    xcb_flush(con);
  }
Пример #3
0
static void
_e_alert_draw_button_text(void)
{
   xcb_char2b_t *str = NULL;
   xcb_query_text_extents_cookie_t cookie;
   xcb_query_text_extents_reply_t *reply;
   int x = 0, w = 0, bw = 0;

   bw = (WINDOW_WIDTH / 2) - 40 - 1;

   /* draw button1 text */
   str = _e_alert_build_string(str1);

   cookie =
     xcb_query_text_extents_unchecked(conn, font, strlen(str1), str);
   reply = xcb_query_text_extents_reply(conn, cookie, NULL);
   if (reply)
     {
        w = reply->overall_width;
        free(reply);
     }
   free(str);

   x = (5 + ((bw - w) / 2));

   xcb_image_text_8(conn, strlen(str1), btn1, gc, x, (10 + fa), str1);

   /* draw button2 text */
   str = _e_alert_build_string(str2);

   cookie =
     xcb_query_text_extents_unchecked(conn, font, strlen(str2), str);
   reply = xcb_query_text_extents_reply(conn, cookie, NULL);
   if (reply)
     {
        w = reply->overall_width;
        free(reply);
     }
   free(str);

   x = (5 + ((bw - w) / 2));

   xcb_image_text_8(conn, strlen(str2), btn2, gc, x, (10 + fa), str2);
}
Пример #4
0
static void
_e_alert_draw_title(void)
{
   int x = 0, y = 0;

   /* draw title */
   x = (2 + 2 + ((WINDOW_WIDTH - 4 - 4 - fw) / 2));
   y = (2 + 2 + fh);

   xcb_image_text_8(conn, strlen(title), win, gc, x, y, title);
}
Пример #5
0
Файл: bar.c Проект: nqv/nilwm
static
void draw_bar_text(struct bar_box_t *box, const char *s, int len) {
    uint32_t vals[2];
    xcb_rectangle_t rect;

    vals[0] = nil_.color.bar_fg;
    vals[1] = nil_.color.bar_bg;
    if (box->w > 0) {           /* clear box before writing text */
        rect.x = box->x;
        rect.y = 0;
        rect.width = box->w;
        rect.height = bar_.h;
        xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND, &vals[1]);
        xcb_poly_fill_rectangle(nil_.con, bar_.win, bar_.gc, 1, &rect);
    }
    /* new pos/size */
    rect.width = cal_text_width(s, len);
    if (NIL_HAS_FLAG(box->flags, BOX_FIXED)) {          /* size is not changed */
        /* text alignment */
        if (NIL_HAS_FLAG(box->flags, BOX_TEXT_CENTER)) {
            rect.x = box->x + CENTER_H_(box->w, rect.width);
        } else if (NIL_HAS_FLAG(box->flags, BOX_TEXT_RIGHT)) {
            rect.x = box->x + box->w - rect.width;
        } else {
            rect.x = box->x;
        }
    } else if (NIL_HAS_FLAG(box->flags, BOX_RIGHT)) {   /* float right */
        rect.x = box->x + box->w - rect.width;
        box->x = rect.x;
        box->w = rect.width;
    } else {                                            /* float left */
        rect.x = box->x;
        box->w = rect.width;
    }
    NIL_LOG("draw text %d in %d %u", rect.x, box->x, box->w);
    xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, vals);
    xcb_image_text_8(nil_.con, len, bar_.win, bar_.gc, rect.x,
        CENTER_V_(bar_.h), s);
}
Пример #6
0
static void
_e_alert_draw_text(void)
{
   char warn[1024], msg[4096], line[1024];
   unsigned int i = 0, j = 0, k = 0;

   if (!tainted)
     {
        if (exit_gdb)
          {
             snprintf(msg, sizeof(msg),
                      "This is not meant to happen and is likely a sign of \n"
                      "a bug in Moksha or the libraries it relies \n"
                      "on. We were not able to generate a backtrace, check \n"
                      "if your 'sysactions.conf' has an 'gdb' action line.\n"
                      "\n"
                      "Please compile latest svn E17 and EFL with\n"
                      "-g and -ggdb3 in your CFLAGS.\n");
          }
        else if (backtrace_str)
          {
             snprintf(msg, sizeof(msg),
                      "This is not meant to happen and is likely a sign of \n"
                      "a bug in Moksha or the libraries it relies \n"
                      "on. You will find an backtrace of E17 (%d) in :\n"
                      "'%s'\n"
                      "Before reporting issue, compile latest E17 and EFL\n"
                      "from svn with '-g -ggdb3' in your CFLAGS.\n"
                      "You can then report this crash on :\n"
                      "http://trac.enlightenment.org/e/.\n",
                      pid, backtrace_str);
          }
        else
          {
             snprintf(msg, sizeof(msg),
                      "This is not meant to happen and is likely a sign of \n"
                      "a bug in Moksha or the libraries it relies \n"
                      "on. You can gdb attach to this process (%d) now \n"
                      "to try debug it or you could logout, or just hit \n"
                      "recover to try and get your desktop back the way \n"
                      "it was.\n"
                      "\n"
                      "Please compile latest svn E17 and EFL with\n"
                      "-g and -ggdb3 in your CFLAGS.\n", pid);
          }
     }
   else
     {
        snprintf(msg, sizeof(msg),
                 "This is not meant to happen and is likely\n"
                 "a sign of a bug, but you are using unsupported\n"
                 "modules; before reporting this issue, please\n"
                 "unload them and try to see if the bug is still\n"
                 "there. Also update to latest svn and be sure to\n"
                 "compile E17 and EFL with -g and -ggdb3 in your CFLAGS");
     }

   strcpy(warn, "");

   for (i = 0; i < sizeof(signal_name) / sizeof(signal_name[0]); ++i)
     if (signal_name[i].signal == sig)
       snprintf(warn, sizeof(warn),
                "This is very bad. Moksha %s'd.",
                signal_name[i].name);

   /* draw text */
   k = (fh + 12);
   xcb_image_text_8(conn, strlen(warn), win, gc,
                    4, (k + fa), warn);
   k += (2 * (fh + 2));
   for (i = 0; msg[i]; )
     {
        line[j++] = msg[i++];
        if (line[j - 1] == '\n')
          {
             line[j - 1] = 0;
             j = 0;
             xcb_image_text_8(conn, strlen(line), win, gc,
                              4, (k + fa), line);
             k += (fh + 2);
          }
     }
}
Пример #7
0
Файл: bar.c Проект: nqv/nilwm
void config_bar() {
    unsigned int i;
    int len, pad;
    xcb_rectangle_t rect;
    uint32_t vals[2];
    char text[3];
    struct bar_box_t *box;

    /* workspace selection area */
    box = &bar_.box[BAR_WS];
    box->x = 0;
    box->w = bar_.h * cfg_.num_workspaces;
    box->flags = BOX_FIXED;
    box->click = &click_ws;

    /* colors */
    vals[0] = nil_.color.bar_fg;
    vals[1] = nil_.color.bar_bg;
    xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND, &vals[1]);

    rect.width = bar_.w;
    rect.height = bar_.h;
    rect.x = 0;
    rect.y = 0;
    xcb_poly_fill_rectangle(nil_.con, bar_.win, bar_.gc, 1, &rect);

    /* workspace numbers */
    xcb_change_gc(nil_.con, bar_.gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, vals);
    rect.x = 0;
    rect.y = (rect.height + nil_.font.ascent + nil_.font.descent) / 2 - nil_.font.descent;
    rect.width = bar_.h;
    for (i = 1; i <= cfg_.num_workspaces; ++i) {
        len = snprintf(text, sizeof(text), "%u", i);
        pad = (rect.width - cal_text_width(text, len)) / 2; /* to align center */
        xcb_image_text_8(nil_.con, len, bar_.win, bar_.gc, rect.x + pad, rect.y, text);
        rect.x += rect.width;
    }
    /* layout symbol (next to ws) */
    box = &bar_.box[BAR_SYM];
    box->x = 0 + bar_.box[BAR_WS].w;
    box->w = 30;
    box->flags = BOX_FIXED | BOX_TEXT_CENTER;
    box->click = &click_sym;
    /* icon tray (right aligned) */
    box = &bar_.box[BAR_ICON];
    box->x = bar_.w;
    box->w = 0;                 /* no icon yet */
    box->flags = BOX_RIGHT;
    box->click = 0;
    /* status (right aligned) */
    box = &bar_.box[BAR_STATUS];
    box->x = bar_.w - bar_.box[BAR_ICON].w;
    box->w = 0;                 /* empty */
    box->flags = BOX_RIGHT;
    box->click = 0;
    /* task (remain) */
    box = &bar_.box[BAR_TASK];
    box->x = bar_.box[BAR_SYM].x + bar_.box[BAR_SYM].w;
    box->w = bar_.box[BAR_STATUS].x - bar_.box[BAR_TASK].x;
    box->flags = BOX_LEFT;
    box->click = 0;
}
Пример #8
0
Файл: bar.c Проект: nqv/nilwm
void text_bar(int x, int y, const char *str) {
    int len;

    len = strlen(str);
    xcb_image_text_8(nil_.con, len, bar_.win, bar_.gc, x, y, str);
}