コード例 #1
0
ファイル: wm.c プロジェクト: DmitryHetman/swc
int
main(int argc, char *argv[])
{
	display = wl_display_create();

	if (!display)
		return EXIT_FAILURE;

	if (wl_display_add_socket(display, NULL) != 0)
		return EXIT_FAILURE;

	if (!swc_initialize(display, NULL, &manager))
		return EXIT_FAILURE;

	swc_add_binding(SWC_BINDING_KEY, SWC_MOD_LOGO, XKB_KEY_Return,
	                &spawn, terminal_command);
	swc_add_binding(SWC_BINDING_KEY, SWC_MOD_LOGO, XKB_KEY_r,
	                &spawn, dmenu_command);
	swc_add_binding(SWC_BINDING_KEY, SWC_MOD_LOGO, XKB_KEY_q,
	                &quit, NULL);

	event_loop = wl_display_get_event_loop(display);
	wl_display_run(display);
	wl_display_destroy(display);

	return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: mockcompositor.cpp プロジェクト: RobinWuDev/Qt
Compositor::Compositor()
    : m_display(wl_display_create())
    , m_time(0)
{
    wl_list_init(&m_outputResources);

    if (wl_display_add_socket(m_display, 0)) {
        fprintf(stderr, "Fatal: Failed to open server socket\n");
        exit(EXIT_FAILURE);
    }

    wl_display_add_global(m_display, &wl_compositor_interface, this, bindCompositor);

    m_data_device_manager.reset(new DataDeviceManager(this, m_display));

    wl_display_init_shm(m_display);

    m_seat.reset(new Seat(this, m_display));
    m_pointer = m_seat->pointer();
    m_keyboard = m_seat->keyboard();

    wl_display_add_global(m_display, &wl_output_interface, this, bindOutput);
    wl_display_add_global(m_display, &wl_shell_interface, this, bindShell);

    m_loop = wl_display_get_event_loop(m_display);
    m_fd = wl_event_loop_get_fd(m_loop);
}
コード例 #3
0
ファイル: compositor.c プロジェクト: jekstrand/wheatley
JNIEXPORT jlong JNICALL
Java_net_jlekstrand_wheatley_wayland_Compositor_createNative(JNIEnv *env,
        jclass cls)
{
    struct wheatley_compositor *wc;

    wc = malloc(sizeof *wc);
    if (wc == NULL) {
        jni_util_throw_by_name(env, "java/lang/OutOfMemoryError", NULL);
        return 0;
    }
    memset(wc, 0, sizeof *wc);

    /* Pass libwlb and libwayland logging through to Android. */
    wlb_log_set_func(wlb_log_android_func);
    wl_debug_set_handler_server(wl_debug_android_func);

    /* XXX: This should be removed at some point */
    setenv("WAYLAND_DEBUG", "server", 1);

    /* XXX: This is hard-coded merely for testing purposes */
    setenv("XDG_RUNTIME_DIR", "/data/data/net.jlekstrand.wheatley/", 1);

    wc->display = wl_display_create();
    if (!wc->display) {
        ALOGD("Failed to create display: %s", strerror(errno));
        goto err_alloc;
    }

    wc->compositor = wlb_compositor_create(wc->display);
    if (!wc->compositor) {
        ALOGD("Failed to create compositor: %s", strerror(errno));
        goto err_display;
    }

    if (wl_display_init_shm(wc->display) < 0) {
        ALOGD("Failed to initialize wl_shm: %s", strerror(errno));
        goto err_compositor;
    }

    wc->wlegl = wlegl_create(wc->compositor);
    if (!wc->wlegl) {
        ALOGD("Failed to initialize android_wlegl: %s", strerror(errno));
        goto err_compositor;
    }

    return (long)(intptr_t)wc;

err_compositor:
    wlb_compositor_destroy(wc->compositor);
err_display:
    wl_display_destroy(wc->display);
err_alloc:
    free(wc);
    jni_util_throw_by_name(env, "java/lang/RuntimeException", NULL);

    return 0;
}
コード例 #4
0
ファイル: compositor.c プロジェクト: qiuTED/wayland
struct wl_display *
wl_compositor_init(int argc, char **argv)
{
    struct lame_compositor *lc;
    struct wl_backend *backend;
    struct fb_fix_screeninfo fix;
    struct fb_var_screeninfo var;
    int fd;

    lc = malloc(sizeof *lc);
    if (lc == NULL)
        return NULL;


    lc->base.interface = &interface;

    fd = open(fb_device, O_RDWR);
    if (fd < 0) {
        fprintf(stderr, "open %s failed: %m\n", fb_device);
        return NULL;
    }

    if (ioctl(fd, FBIOGET_FSCREENINFO, &fix) < 0) {
        fprintf(stderr, "fb get fixed failed\n");
        return NULL;
    }

    if (ioctl(fd, FBIOGET_VSCREENINFO, &var) < 0) {
        fprintf(stderr, "fb get fixed failed\n");
        return NULL;
    }

    backend = wl_backend_create("shm", NULL);
    lc->wl_display = wl_display_create(backend, &lc->base);
    if (lc->wl_display == NULL) {
        wl_backend_destroy(backend);
        return NULL;
    }

    lc->stride = fix.line_length;
    lc->width = var.xres;
    lc->height = var.yres;
    lc->fb = mmap(NULL, lc->stride * lc->height,
                  PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    close(fd);
    if (lc->fb == MAP_FAILED) {
        fprintf(stderr, "fb map failed\n");
        return NULL;
    }

    create_input_devices (lc->wl_display);
    return lc->wl_display;
}
コード例 #5
0
ファイル: meta-wayland.c プロジェクト: wolfv/mutter
void
meta_wayland_pre_clutter_init (void)
{
  MetaWaylandCompositor *compositor = &_meta_wayland_compositor;

  meta_wayland_compositor_init (compositor);

  /* Set up our logging. */
  wl_log_set_handler_server (meta_wayland_log_func);

  compositor->wayland_display = wl_display_create ();
  if (compositor->wayland_display == NULL)
    g_error ("Failed to create the global wl_display");

  clutter_wayland_set_compositor_display (compositor->wayland_display);
}
コード例 #6
0
ファイル: flower.c プロジェクト: qiuTED/wayland
int main(int argc, char *argv[])
{
	struct wl_display *display;
	cairo_surface_t *s;
	struct timespec ts;
	GMainLoop *loop;
	GSource *source;
	struct flower flower;

	loop = g_main_loop_new(NULL, FALSE);

	display = wl_display_create(socket_name);
	if (display == NULL) {
		fprintf(stderr, "failed to create display: %m\n");
		return -1;
	}

	source = wayland_source_new(display);
	g_source_attach(source, NULL);

	flower.x = 512;
	flower.y = 384;
	flower.width = 200;
	flower.height = 200;
	flower.surface = wl_display_create_surface(display);

	clock_gettime(CLOCK_MONOTONIC, &ts);
	srandom(ts.tv_nsec);
	flower.i = ts.tv_nsec;

	s = draw_stuff(flower.width, flower.height);
	flower.buffer = wl_buffer_create_from_cairo_surface(display, s);

	wl_surface_attach_buffer(flower.surface, flower.buffer);

	g_timeout_add(20, move_flower, &flower);

	g_main_loop_run(loop);

	return 0;
}
コード例 #7
0
ファイル: cogland.c プロジェクト: 3v1n0/cogl
int
main (int argc, char **argv)
{
  CoglandCompositor compositor;
  GMainLoop *loop;
  CoglError *error = NULL;
  GError *gerror = NULL;
  CoglVertexP2C4 triangle_vertices[] = {
      {0, 0.7, 0xff, 0x00, 0x00, 0xff},
      {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
      {0.7, -0.7, 0x00, 0x00, 0xff, 0xff}
  };
  GSource *cogl_source;

  if (!process_arguments (&argc, &argv, &gerror))
    {
      fprintf (stderr, "%s\n", gerror->message);
      return EXIT_FAILURE;
    }

  memset (&compositor, 0, sizeof (compositor));

  compositor.wayland_display = wl_display_create ();
  if (compositor.wayland_display == NULL)
    g_error ("failed to create wayland display");

  wl_list_init (&compositor.frame_callbacks);

  if (!wl_display_add_global (compositor.wayland_display,
                              &wl_compositor_interface,
                              &compositor,
                              compositor_bind))
    g_error ("Failed to register wayland compositor object");

  wl_display_init_shm (compositor.wayland_display);

  loop = g_main_loop_new (NULL, FALSE);
  compositor.wayland_loop =
    wl_display_get_event_loop (compositor.wayland_display);
  compositor.wayland_event_source =
    wayland_event_source_new (compositor.wayland_display);
  g_source_attach (compositor.wayland_event_source, NULL);

  /* We want Cogl to use an EGL renderer because otherwise it won't
   * set up the wl_drm object and only SHM buffers will work. */
  compositor.cogl_context =
    create_cogl_context (&compositor,
                         TRUE /* use EGL constraint */,
                         &error);
  if (compositor.cogl_context == NULL)
    {
      /* If we couldn't get an EGL context then try any type of
       * context */
      cogl_error_free (error);
      error = NULL;

      compositor.cogl_context =
        create_cogl_context (&compositor,
                             FALSE, /* don't set EGL constraint */
                             &error);

      if (compositor.cogl_context)
        g_warning ("Failed to create context with EGL constraint, "
                   "falling back");
      else
        g_error ("Failed to create a Cogl context: %s\n", error->message);
    }

  compositor.virtual_width = 800;
  compositor.virtual_height = 600;

  if (option_multiple_outputs)
    {
      int hw = compositor.virtual_width / 2;
      int hh = compositor.virtual_height / 2;
      /* Emulate compositing with multiple monitors... */
      cogland_compositor_create_output (&compositor, 0, 0, hw, hh);
      cogland_compositor_create_output (&compositor, hw, 0, hw, hh);
      cogland_compositor_create_output (&compositor, 0, hh, hw, hh);
      cogland_compositor_create_output (&compositor, hw, hh, hw, hh);
    }
  else
    {
      cogland_compositor_create_output (&compositor,
                                        0, 0,
                                        compositor.virtual_width,
                                        compositor.virtual_height);
    }

  if (wl_display_add_global (compositor.wayland_display, &wl_shell_interface,
                             &compositor, bind_shell) == NULL)
    g_error ("Failed to register a global shell object");

  if (wl_display_add_socket (compositor.wayland_display, "wayland-0"))
    g_error ("Failed to create socket");

  compositor.triangle = cogl_primitive_new_p2c4 (compositor.cogl_context,
                                                 COGL_VERTICES_MODE_TRIANGLES,
                                                 3, triangle_vertices);
  compositor.triangle_pipeline = cogl_pipeline_new (compositor.cogl_context);

  cogl_source = cogl_glib_source_new (compositor.cogl_context,
                                      G_PRIORITY_DEFAULT);

  g_source_attach (cogl_source, NULL);

  g_main_loop_run (loop);

  return 0;
}
コード例 #8
0
ファイル: cogland.c プロジェクト: recrack/cogl-android
int
main (int argc, char **argv)
{
  CoglandCompositor compositor;
  GMainLoop *loop;
  CoglError *error = NULL;
  CoglVertexP2C4 triangle_vertices[] = {
      {0, 0.7, 0xff, 0x00, 0x00, 0x80},
      {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
      {0.7, -0.7, 0x00, 0x00, 0xff, 0xff}
  };
  GSource *cogl_source;

  memset (&compositor, 0, sizeof (compositor));

  compositor.wayland_display = wl_display_create ();
  if (compositor.wayland_display == NULL)
    g_error ("failed to create wayland display");

  g_queue_init (&compositor.frame_callbacks);

  if (!wl_display_add_global (compositor.wayland_display,
                              &wl_compositor_interface,
                              &compositor,
                              compositor_bind))
    g_error ("Failed to register wayland compositor object");

  compositor.wayland_shm = wl_shm_init (compositor.wayland_display,
                                        &shm_callbacks);
  if (!compositor.wayland_shm)
    g_error ("Failed to allocate setup wayland shm callbacks");

  loop = g_main_loop_new (NULL, FALSE);
  compositor.wayland_loop =
    wl_display_get_event_loop (compositor.wayland_display);
  compositor.wayland_event_source =
    wayland_event_source_new (compositor.wayland_loop);
  g_source_attach (compositor.wayland_event_source, NULL);

  compositor.cogl_display = cogl_display_new (NULL, NULL);
  cogl_wayland_display_set_compositor_display (compositor.cogl_display,
                                               compositor.wayland_display);

  compositor.cogl_context = cogl_context_new (compositor.cogl_display, &error);
  if (!compositor.cogl_context)
    g_error ("Failed to create a Cogl context: %s\n", error->message);

  compositor.virtual_width = 640;
  compositor.virtual_height = 480;

  /* Emulate compositing with multiple monitors... */
  cogland_compositor_create_output (&compositor, 0, 0, 320, 240);
  cogland_compositor_create_output (&compositor, 320, 0, 320, 240);
  cogland_compositor_create_output (&compositor, 0, 240, 320, 240);
  cogland_compositor_create_output (&compositor, 320, 240, 320, 240);

  if (wl_display_add_global (compositor.wayland_display, &wl_shell_interface,
                             &compositor, bind_shell) == NULL)
    g_error ("Failed to register a global shell object");

  if (wl_display_add_socket (compositor.wayland_display, "wayland-0"))
    g_error ("Failed to create socket");

  compositor.triangle = cogl_primitive_new_p2c4 (compositor.cogl_context,
                                                 COGL_VERTICES_MODE_TRIANGLES,
                                                 3, triangle_vertices);
  compositor.triangle_pipeline = cogl_pipeline_new (compositor.cogl_context);

  g_timeout_add (16, paint_cb, &compositor);

  cogl_source = cogl_glib_source_new (compositor.cogl_context,
                                      G_PRIORITY_DEFAULT);

  g_source_attach (cogl_source, NULL);

  g_main_loop_run (loop);

  return 0;
}
コード例 #9
0
ファイル: wlc.c プロジェクト: UIKit0/wlc
WLC_API bool
wlc_init(const struct wlc_interface *interface, int argc, char *argv[])
{
   assert(interface);

   if (!interface)
      die("no wlc_interface was given");

   if (wlc.display)
      return true;

   memset(&wlc, 0, sizeof(wlc));

   wl_log_set_handler_server(wl_cb_log);

   for (int i = 1; i < argc; ++i) {
      if (chck_cstreq(argv[i], "--log")) {
         if (i + 1 >= argc)
            die("--log takes an argument (filename)");
         wlc_set_log_file(fopen(argv[++i], "a"));
      }
   }

   unsetenv("TERM");
   const char *x11display = getenv("DISPLAY");
   bool privilidged = false;
   const bool has_logind  = wlc_logind_available();

   if (getuid() != geteuid() || getgid() != getegid()) {
      wlc_log(WLC_LOG_INFO, "Doing work on SUID/SGID side and dropping permissions");
      privilidged = true;
   } else if (getuid() == 0) {
      die("Do not run wlc compositor as root");
   } else if (!x11display && !has_logind && access("/dev/input/event0", R_OK | W_OK) != 0) {
      die("Not running from X11 and no access to /dev/input/event0 or logind available");
   }

#ifndef NDEBUG
   {
      struct sigaction action = {
         .sa_handler = backtrace
      };
      sigaction(SIGABRT, &action, NULL);
      sigaction(SIGSEGV, &action, NULL);

      // XXX: Some weird sigfpes seems to come when running
      // wlc compositor inside wlc compositor (X11 backend).
      // Seems to be caused by resolution changes and mouse clicks.
      // Gather more information about this later and see what's going on.
      if (!getenv("WAYLAND_DISPLAY"))
         fpesetup(&action);
   }
#endif

   int vt = 0;

#ifdef HAS_LOGIND
   // Init logind if we are not running as SUID.
   // We need event loop for logind to work, and thus we won't allow it on SUID process.
   if (!privilidged && !x11display && has_logind) {
      if (!(wlc.display = wl_display_create()))
         die("Failed to create wayland display");
      if (!(vt = wlc_logind_init("seat0")))
         die("Failed to init logind");
   }
#else
   (void)privilidged;
#endif

   if (!x11display)
      wlc_tty_init(vt);

   // -- we open tty before dropping permissions
   //    so the fd process can also handle cleanup in case of crash
   //    if logind initialized correctly, fd process does nothing but handle crash.

   {
      struct wl_display *display = wlc.display;
      wlc.display = NULL;
      wlc_fd_init(argc, argv, (vt != 0));
      wlc.display = display;
   }


   // -- permissions are now dropped

   wl_signal_init(&wlc.signals.terminate);
   wl_signal_init(&wlc.signals.activate);
   wl_signal_init(&wlc.signals.compositor);
   wl_signal_init(&wlc.signals.focus);
   wl_signal_init(&wlc.signals.surface);
   wl_signal_init(&wlc.signals.input);
   wl_signal_init(&wlc.signals.output);
   wl_signal_init(&wlc.signals.render);
   wl_signal_init(&wlc.signals.xwayland);
   wl_signal_add(&wlc.signals.compositor, &compositor_listener);

   if (!wlc_resources_init())
      die("Failed to init resource manager");

   if (!wlc.display && !(wlc.display = wl_display_create()))
      die("Failed to create wayland display");

   const char *socket_name;
   if (!(socket_name = wl_display_add_socket_auto(wlc.display)))
      die("Failed to add socket to wayland display");

   if (socket_name) // shut up static analyze
      setenv("WAYLAND_DISPLAY", socket_name, true);

   if (wl_display_init_shm(wlc.display) != 0)
      die("Failed to init shm");

   if (!wlc_udev_init())
      die("Failed to init udev");

   const char *libinput = getenv("WLC_LIBINPUT");
   if (!x11display || (libinput && !chck_cstreq(libinput, "0"))) {
      if (!wlc_input_init())
         die("Failed to init input");
   }

   memcpy(&wlc.interface, interface, sizeof(wlc.interface));

   if (!wlc_compositor(&wlc.compositor))
      die("Failed to init compositor");

   const char *xwayland = getenv("WLC_XWAYLAND");
   if (!xwayland || !chck_cstreq(xwayland, "0")) {
      if (!(wlc_xwayland_init()))
         die("Failed to init xwayland");
   } else {
      wlc.set_ready_on_run = true;
   }

   wlc_set_active(true);
   return wlc_compositor_is_good(&wlc.compositor);
}
コード例 #10
0
ファイル: wlc.c プロジェクト: scarabeusiv/wlc
WLC_API bool
wlc_init(const struct wlc_interface *interface, int argc, char *argv[])
{
   assert(interface);

   if (!interface)
      die("no wlc_interface was given");

   if (wlc.display)
      return true;

   // reset wlc state, but keep log function
   void *log_fun = wlc.log_fun;
   memset(&wlc, 0, sizeof(wlc));
   wlc.log_fun = log_fun;

   wl_log_set_handler_server(wl_cb_log);

   unsetenv("TERM");
   const char *x11display = getenv("DISPLAY");
   bool privileged = false;
   const bool has_logind = wlc_logind_available();

   if (getuid() != geteuid() || getgid() != getegid()) {
      wlc_log(WLC_LOG_INFO, "Doing work on SUID/SGID side and dropping permissions");
      privileged = true;
   } else if (getuid() == 0) {
      die("Do not run wlc compositor as root");
   } else if (!x11display && !has_logind && access("/dev/input/event0", R_OK | W_OK) != 0) {
      die("Not running from X11 and no access to /dev/input/event0 or logind available");
   }

   int vt = 0;

#ifdef HAS_LOGIND
   // Init logind if we are not running as SUID.
   // We need event loop for logind to work, and thus we won't allow it on SUID process.
   if (!privileged && !x11display && has_logind) {
      if (!(wlc.display = wl_display_create()))
         die("Failed to create wayland display");
      if (!(vt = wlc_logind_init("seat0")))
         die("Failed to init logind");
   }
#else
   (void)privileged;
#endif

   if (!x11display)
      wlc_tty_init(vt);

   // -- we open tty before dropping permissions
   //    so the fd process can also handle cleanup in case of crash
   //    if logind initialized correctly, fd process does nothing but handle crash.

   {
      struct wl_display *display = wlc.display;
      wlc.display = NULL;
      wlc_fd_init(argc, argv, (vt != 0));
      wlc.display = display;
   }

   // -- permissions are now dropped

   wl_signal_init(&wlc.signals.terminate);
   wl_signal_init(&wlc.signals.activate);
   wl_signal_init(&wlc.signals.compositor);
   wl_signal_init(&wlc.signals.focus);
   wl_signal_init(&wlc.signals.surface);
   wl_signal_init(&wlc.signals.input);
   wl_signal_init(&wlc.signals.output);
   wl_signal_init(&wlc.signals.render);
   wl_signal_init(&wlc.signals.xwayland);
   wl_signal_add(&wlc.signals.compositor, &compositor_listener);

   if (!wlc_resources_init())
      die("Failed to init resource manager");

   if (!wlc.display && !(wlc.display = wl_display_create()))
      die("Failed to create wayland display");

   const char *socket_name;
   if (!(socket_name = wl_display_add_socket_auto(wlc.display)))
      die("Failed to add socket to wayland display");

   if (socket_name) // shut up static analyze
      setenv("WAYLAND_DISPLAY", socket_name, true);

   if (wl_display_init_shm(wlc.display) != 0)
      die("Failed to init shm");

   if (!wlc_udev_init())
      die("Failed to init udev");

   const char *libinput = getenv("WLC_LIBINPUT");
   if (!x11display || (libinput && !chck_cstreq(libinput, "0"))) {
      if (!wlc_input_init())
         die("Failed to init input");
   }

   if (!wlc_compositor(&wlc.compositor))
      die("Failed to init compositor");

   memcpy(&wlc.interface, interface, sizeof(wlc.interface));
   return true;
}