Beispiel #1
0
int xeb_loop(void) {
    Display *display = XOpenDisplay(NULL);
    if (!display) {
        fprintf(stderr, "Failed to open display\n");
        return -1;
    }

    int screen_count = ScreenCount(display);
    Window roots[screen_count];
    struct dimensions dimens[screen_count];

    for (int i = 0; i < screen_count; i++) {
        roots[i] = RootWindow(display, i);

        XWindowAttributes attrs;
        Status status = XGetWindowAttributes(display, roots[i], &attrs);
        if (!status) {
            fprintf(stderr, "Failed to get root window attributes for screen: %d\n", i);
            return -1;
        }
        dimens[i].width = attrs.width;
        dimens[i].height = attrs.height;

        XSelectInput(display, roots[i], StructureNotifyMask);
    }

    for (;;) {
        XEvent e;
        XNextEvent(display, &e);
        if (e.type == ConfigureNotify) {
            XConfigureEvent xce = e.xconfigure;
            for (int i = 0; i < screen_count; i++) {
                if (xce.window == roots[i]) {
                    if (xce.width != dimens[i].width || xce.height != dimens[i].height) {
                        dimens[i].width = xce.width;
                        dimens[i].height = xce.height;
                        call_callbacks(ResolutionChange);
                    }
                    break;
                }
            }
        }
    }
}
Beispiel #2
0
void GenericWidget<T>::update() {
    if (last_val_ != *monitor_) {
        call_callbacks();
        last_val_ = *monitor_;
    }
}
Beispiel #3
0
static int bin_handle_req(struct tcp_req *req,
							struct tcp_connection *con, int _max_msg_chunks)
{
	long size;

	if (req->complete){
		/* update the timeout - we succesfully read the request */
		tcp_conn_set_lifetime( con, tcp_con_lifetime);
		con->timeout = con->lifetime;

		LM_DBG("completely received a message\n");
		/* rcv.bind_address should always be !=0 */
		/* just for debugging use sendipv4 as receiving socket  FIXME*/
		con->rcv.proto_reserved1=con->id; /* copy the id */

		/* prepare for next request */
		size=req->pos - req->parsed;

		if (!size) {
			/* did not read any more things -  we can release
			 * the connection */
			LM_DBG("Nothing more to read on TCP conn %p, currently in state %d \n",
				con,con->state);
			if (req != &bin_current_req) {
				/* we have the buffer in the connection tied buff -
				 *	detach it , release the conn and free it afterwards */
				con->con_req = NULL;
			}
		} else {
			LM_DBG("We still have things on the pipe - "
				"keeping connection \n");
		}
		
		/* give the message to the registered functions */
		call_callbacks(req->buf, &con->rcv);


		if (!size && req != &bin_current_req) {
			/* if we no longer need this tcp_req
			 * we can free it now */
			pkg_free(req);
		}

		if (size)
			memmove(req->buf, req->parsed, size);

		init_tcp_req(req, size);
		con->msg_attempts = 0;

		/* if we still have some unparsed bytes, try to  parse them too*/
		if (size) 
			return 1;
	} else {  
		/* request not complete - check the if the thresholds are exceeded */
		if (con->msg_attempts==0)
			/* if first iteration, set a short timeout for reading
			 * a whole SIP message */
			con->timeout = get_ticks() + tcp_max_msg_time;

		con->msg_attempts ++;
		if (con->msg_attempts == _max_msg_chunks) {
			LM_ERR("Made %u read attempts but message is not complete yet - "
				   "closing connection \n",con->msg_attempts);
			goto error;
		}

		if (req == &bin_current_req) {
			/* let's duplicate this - most likely another conn will come in */

			LM_DBG("We didn't manage to read a full request\n");
			con->con_req = pkg_malloc(sizeof(struct tcp_req));
			if (con->con_req == NULL) {
				LM_ERR("No more mem for dynamic con request buffer\n");
				goto error;
			}

			if (req->pos != req->buf) {
				/* we have read some bytes */
				memcpy(con->con_req->buf,req->buf,req->pos-req->buf);
				con->con_req->pos = con->con_req->buf + (req->pos-req->buf);
			} else {
				con->con_req->pos = con->con_req->buf;
			}

			if (req->parsed != req->buf)
				con->con_req->parsed =con->con_req->buf+(req->parsed-req->buf);
			else
				con->con_req->parsed = con->con_req->buf;

			con->con_req->complete=req->complete;
			con->con_req->content_len=req->content_len;
			con->con_req->error = req->error;
		}
	}

	/* everything ok */
	return 0;
error:
	/* report error */
	return -1;
}