Beispiel #1
0
void Client::updateState(xcb_ewmh_connection_t* ewmhConn)
{
    xcb_connection_t* conn = ewmhConn->connection;
    xcb_get_geometry_cookie_t geomCookie;
    if (!mOwned)
        geomCookie = xcb_get_geometry_unchecked(conn, mWindow);
    const xcb_get_property_cookie_t normalHintsCookie = xcb_icccm_get_wm_normal_hints(conn, mWindow);
    const xcb_get_property_cookie_t leaderCookie = xcb_get_property(conn, 0, mWindow, Atoms::WM_CLIENT_LEADER, XCB_ATOM_WINDOW, 0, 1);
    const xcb_get_property_cookie_t transientCookie = xcb_icccm_get_wm_transient_for(conn, mWindow);
    const xcb_get_property_cookie_t hintsCookie = xcb_icccm_get_wm_hints(conn, mWindow);
    const xcb_get_property_cookie_t classCookie = xcb_icccm_get_wm_class(conn, mWindow);
    const xcb_get_property_cookie_t nameCookie = xcb_icccm_get_wm_name(conn, mWindow);
    const xcb_get_property_cookie_t protocolsCookie = xcb_icccm_get_wm_protocols(conn, mWindow, Atoms::WM_PROTOCOLS);
    const xcb_get_property_cookie_t strutCookie = xcb_ewmh_get_wm_strut(ewmhConn, mWindow);
    const xcb_get_property_cookie_t partialStrutCookie = xcb_ewmh_get_wm_strut_partial(ewmhConn, mWindow);
    const xcb_get_property_cookie_t stateCookie = xcb_ewmh_get_wm_state(ewmhConn, mWindow);
    const xcb_get_property_cookie_t typeCookie = xcb_ewmh_get_wm_window_type(ewmhConn, mWindow);
    const xcb_get_property_cookie_t pidCookie = xcb_ewmh_get_wm_pid(ewmhConn, mWindow);

    if (!mOwned)
        updateSize(conn, geomCookie);
    updateNormalHints(conn, normalHintsCookie);
    updateLeader(conn, leaderCookie);
    updateTransient(conn, transientCookie);
    updateHints(conn, hintsCookie);
    updateClass(conn, classCookie);
    updateName(conn, nameCookie);
    updateProtocols(conn, protocolsCookie);
    updateStrut(ewmhConn, strutCookie);
    updatePartialStrut(ewmhConn, partialStrutCookie);
    updateEwmhState(ewmhConn, stateCookie);
    updateWindowTypes(ewmhConn, typeCookie);
    updatePid(ewmhConn, pidCookie);
}
Beispiel #2
0
void Toolbar::toggleAutoHide(void) {
  bool do_auto_hide = !_screen->resource().toolbarOptions().auto_hide;

  updateStrut();
  if (_screen->slit())
    _screen->slit()->reposition();

  if (!do_auto_hide && hidden) {
    // force the toolbar to be visible
    if (hide_timer->isTiming()) hide_timer->stop();
    hide_timer->fireTimeout();
  }
}
Beispiel #3
0
void Client::propertyNotify(xcb_atom_t atom)
{
#warning Need to notify js that properties have changed
    warning() << "Got propertyNotify" << Atoms::name(atom) << mWindow;
    auto ewmhConnection = WindowManager::instance()->ewmhConnection();
    auto conn = ewmhConnection->connection;
    if (atom == XCB_ATOM_WM_NORMAL_HINTS) {
        const xcb_get_property_cookie_t normalHintsCookie = xcb_icccm_get_wm_normal_hints(conn, mWindow);
        updateNormalHints(conn, normalHintsCookie);
    } else if (atom == XCB_ATOM_WM_TRANSIENT_FOR) {
        const xcb_get_property_cookie_t transientCookie = xcb_icccm_get_wm_transient_for(conn, mWindow);
        updateTransient(conn, transientCookie);
    } else if (atom == Atoms::WM_CLIENT_LEADER) {
        const xcb_get_property_cookie_t leaderCookie = xcb_get_property(conn, 0, mWindow, Atoms::WM_CLIENT_LEADER, XCB_ATOM_WINDOW, 0, 1);
        updateLeader(conn, leaderCookie);
    } else if (atom == XCB_ATOM_WM_HINTS) {
        const xcb_get_property_cookie_t hintsCookie = xcb_icccm_get_wm_hints(conn, mWindow);
        updateHints(conn, hintsCookie);
    } else if (atom == XCB_ATOM_WM_CLASS) {
        const xcb_get_property_cookie_t classCookie = xcb_icccm_get_wm_class(conn, mWindow);
        updateClass(conn, classCookie);
    } else if (atom == XCB_ATOM_WM_NAME) {
        const xcb_get_property_cookie_t nameCookie = xcb_icccm_get_wm_name(conn, mWindow);
        updateName(conn, nameCookie);
    } else if (atom == Atoms::WM_PROTOCOLS) {
        const xcb_get_property_cookie_t protocolsCookie = xcb_icccm_get_wm_protocols(conn, mWindow, Atoms::WM_PROTOCOLS);
        updateProtocols(conn, protocolsCookie);
    } else if (atom == ewmhConnection->_NET_WM_STRUT) {
        const xcb_get_property_cookie_t strutCookie = xcb_ewmh_get_wm_strut(ewmhConnection, mWindow);
        updateStrut(ewmhConnection, strutCookie);
    } else if (atom == ewmhConnection->_NET_WM_STRUT_PARTIAL) {
        const xcb_get_property_cookie_t partialStrutCookie = xcb_ewmh_get_wm_strut_partial(ewmhConnection, mWindow);
        updatePartialStrut(ewmhConnection, partialStrutCookie);
    } else if (atom == ewmhConnection->_NET_WM_STATE) {
        const xcb_get_property_cookie_t stateCookie = xcb_ewmh_get_wm_state(ewmhConnection, mWindow);
        updateEwmhState(ewmhConnection, stateCookie);
    } else if (atom == ewmhConnection->_NET_WM_WINDOW_TYPE) {
        const xcb_get_property_cookie_t typeCookie = xcb_ewmh_get_wm_window_type(ewmhConnection, mWindow);
        updateWindowTypes(ewmhConnection, typeCookie);
    } else if (atom == ewmhConnection->_NET_WM_PID) {
        const xcb_get_property_cookie_t pidCookie = xcb_ewmh_get_wm_pid(ewmhConnection, mWindow);
        updatePid(ewmhConnection, pidCookie);
    } else {
        warning() << "Unhandled propertyNotify atom" << Atoms::name(atom);
    }
}
Beispiel #4
0
void Toolbar::reconfigure(void) {
  ScreenResource &resource = _screen->resource();
  const ToolbarOptions &options = resource.toolbarOptions();
  const ToolbarStyle &style = resource.toolbarStyle();

  unsigned int width = (_screen->screenInfo().width() *
                        options.width_percent) / 100;

  const unsigned int border_width = style.toolbar.borderWidth();
  const unsigned int extra =
    style.frame_margin == 0 ? style.button.borderWidth() : 0;
  frame.rect.setSize(width, style.toolbar_height);

  int x, y;
  switch (options.placement) {
  case TopLeft:
  case TopRight:
  case TopCenter:
    switch (options.placement) {
    case TopLeft:
      x = 0;
      break;
    case TopRight:
      x = _screen->screenInfo().width() - frame.rect.width();
      break;
    default:
      x = (_screen->screenInfo().width() - frame.rect.width()) / 2;
      break;
    }
    y = 0;
    frame.y_hidden = style.hidden_height - frame.rect.height();
    break;

  case BottomLeft:
  case BottomRight:
  case BottomCenter:
  default:
    switch (options.placement) {
    case BottomLeft:
      x = 0;
      break;
    case BottomRight:
      x = _screen->screenInfo().width() - frame.rect.width();
      break;
    default:
      x = (_screen->screenInfo().width() - frame.rect.width()) / 2;
      break;
    }
    y = _screen->screenInfo().height() - frame.rect.height();
    frame.y_hidden = _screen->screenInfo().height() - style.hidden_height;
    break;
  }

  frame.rect.setPos(x, y);

  updateStrut();

  time_t ttmp = time(NULL);

  unsigned int clock_w = 0u, label_w = 0u;

  if (ttmp != -1) {
    struct tm *tt = localtime(&ttmp);
    if (tt) {
      char t[1024];
      int len = strftime(t, 1024, options.strftime_format.c_str(), tt);
      if (len == 0) { // invalid time format found
        // so use the default
        const_cast<std::string &>(options.strftime_format) = "%I:%M %p";
        len = strftime(t, 1024, options.strftime_format.c_str(), tt);
      }
      /*
       * find the length of the rendered string and add room for two extra
       * characters to it.  This allows for variable width output of the fonts.
       * two 'w' are used to get the widest possible width
       */
      clock_w =
        bt::textRect(_screen->screenNumber(), style.font,
                     bt::toUnicode(t)).width() +
        bt::textRect(_screen->screenNumber(), style.font,
                     bt::toUnicode("ww")).width();
    }
  }

  for (unsigned int i = 0; i < _screen->workspaceCount(); i++) {
    width =
      bt::textRect(_screen->screenNumber(), style.font,
                   _screen->resource().workspaceName(i)).width();
    label_w = std::max(label_w, width);
  }

  label_w = clock_w = std::max(label_w, clock_w) + (style.label_margin * 2);

  unsigned int window_label_w =
    (frame.rect.width() - (border_width * 2)
     - (clock_w + (style.button_width * 4) + label_w
        + (style.frame_margin * 8))
     + extra*6);

  XMoveResizeWindow(display, frame.window, frame.rect.x(),
                    hidden ? frame.y_hidden : frame.rect.y(),
                    frame.rect.width(), frame.rect.height());

  // workspace label
  frame.slabel_rect.setRect(border_width + style.frame_margin,
                            border_width + style.frame_margin,
                            label_w,
                            style.label_height);
  // previous workspace button
  frame.ps_rect.setRect(border_width + (style.frame_margin * 2) + label_w
                        - extra,
                        border_width + style.frame_margin,
                        style.button_width,
                        style.button_width);
  // next workspace button
  frame.ns_rect.setRect(border_width + (style.frame_margin * 3)
                        + label_w + style.button_width - (extra * 2),
                        border_width + style.frame_margin,
                        style.button_width,
                        style.button_width);
  // window label
  frame.wlabel_rect.setRect(border_width + (style.frame_margin * 4)
                            + (style.button_width * 2) + label_w - (extra * 3),
                            border_width + style.frame_margin,
                            window_label_w,
                            style.label_height);
  // previous window button
  frame.pw_rect.setRect(border_width + (style.frame_margin * 5)
                        + (style.button_width * 2) + label_w
                        + window_label_w - (extra * 4),
                        border_width + style.frame_margin,
                        style.button_width,
                        style.button_width);
  // next window button
  frame.nw_rect.setRect(border_width + (style.frame_margin * 6)
                        + (style.button_width * 3) + label_w
                        + window_label_w - (extra * 5),
                        border_width + style.frame_margin,
                        style.button_width,
                        style.button_width);
  // clock
  frame.clock_rect.setRect(frame.rect.width() - clock_w - style.frame_margin
                           - border_width,
                           border_width + style.frame_margin,
                           clock_w,
                           style.label_height);

  XMoveResizeWindow(display, frame.workspace_label,
                    frame.slabel_rect.x(), frame.slabel_rect.y(),
                    frame.slabel_rect.width(), frame.slabel_rect.height());
  XMoveResizeWindow(display, frame.psbutton,
                    frame.ps_rect.x(), frame.ps_rect.y(),
                    frame.ps_rect.width(), frame.ps_rect.height());
  XMoveResizeWindow(display, frame.nsbutton,
                    frame.ns_rect.x(), frame.ns_rect.y(),
                    frame.ns_rect.width(), frame.ns_rect.height());
  XMoveResizeWindow(display, frame.window_label,
                    frame.wlabel_rect.x(), frame.wlabel_rect.y(),
                    frame.wlabel_rect.width(), frame.wlabel_rect.height());
  XMoveResizeWindow(display, frame.pwbutton,
                    frame.pw_rect.x(), frame.pw_rect.y(),
                    frame.pw_rect.width(), frame.pw_rect.height());
  XMoveResizeWindow(display, frame.nwbutton,
                    frame.nw_rect.x(), frame.nw_rect.y(),
                    frame.nw_rect.width(), frame.nw_rect.height());
  XMoveResizeWindow(display, frame.clock,
                    frame.clock_rect.x(), frame.clock_rect.y(),
                    frame.clock_rect.width(), frame.clock_rect.height());

  frame.base =
    bt::PixmapCache::find(_screen->screenNumber(), style.toolbar,
                          frame.rect.width(), frame.rect.height(),
                          frame.base);
  frame.slabel =
    bt::PixmapCache::find(_screen->screenNumber(), style.slabel,
                          frame.slabel_rect.width(),
                          frame.slabel_rect.height(),
                          frame.slabel);
  frame.wlabel =
    bt::PixmapCache::find(_screen->screenNumber(), style.wlabel,
                          frame.wlabel_rect.width(),
                          frame.wlabel_rect.height(),
                          frame.wlabel);
  frame.clk =
    bt::PixmapCache::find(_screen->screenNumber(), style.clock,
                          frame.clock_rect.width(),
                          frame.clock_rect.height(),
                          frame.clk);
  frame.button =
    bt::PixmapCache::find(_screen->screenNumber(), style.button,
                          style.button_width, style.button_width,
                          frame.button);
  frame.pbutton =
    bt::PixmapCache::find(_screen->screenNumber(),
                          style.pressed,
                          style.button_width, style.button_width,
                          frame.pbutton);

  XClearArea(display, frame.window, 0, 0,
             frame.rect.width(), frame.rect.height(), True);

  XClearArea(display, frame.workspace_label, 0, 0,
             label_w, style.label_height, True);
  XClearArea(display, frame.window_label, 0, 0,
             window_label_w, style.label_height, True);
  XClearArea(display, frame.clock, 0, 0,
             clock_w, style.label_height, True);

  XClearArea(display, frame.psbutton, 0, 0,
             style.button_width, style.button_width, True);
  XClearArea(display, frame.nsbutton, 0, 0,
             style.button_width, style.button_width, True);
  XClearArea(display, frame.pwbutton, 0, 0,
             style.button_width, style.button_width, True);
  XClearArea(display, frame.nwbutton, 0, 0,
             style.button_width, style.button_width, True);
}