#include "wayland-client.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @page page_wlr_layer_shell_v1_unstable_v1 The wlr_layer_shell_v1_unstable_v1 protocol
* @section page_ifaces_wlr_layer_shell_v1_unstable_v1 Interfaces
* - @subpage page_iface_zwlr_layer_shell_v1 - create surfaces that are layers of the desktop
* - @subpage page_iface_zwlr_layer_surface_v1 - layer metadata interface
* @section page_copyright_wlr_layer_shell_v1_unstable_v1 Copyright
*
*
* Copyright © 2017 Drew DeVault
*
* Permission to use, copy, modify, distribute, and sell this
* software and its documentation for any purpose is hereby granted
* without fee, provided that the above copyright notice appear in
* all copies and that both that copyright notice and this permission
* notice appear in supporting documentation, and that the name of
* the copyright holders not be used in advertising or publicity
* pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
* THIS SOFTWARE.
*
*/
struct wl_output;
struct wl_surface;
struct xdg_popup;
struct zwlr_layer_shell_v1;
struct zwlr_layer_surface_v1;
/**
* @page page_iface_zwlr_layer_shell_v1 zwlr_layer_shell_v1
* @section page_iface_zwlr_layer_shell_v1_desc Description
*
* Clients can use this interface to assign the surface_layer role to
* wl_surfaces. Such surfaces are assigned to a "layer" of the output and
* rendered with a defined z-depth respective to each other. They may also be
* anchored to the edges and corners of a screen and specify input handling
* semantics. This interface should be suitable for the implementation of
* many desktop shell components, and a broad number of other applications
* that interact with the desktop.
* @section page_iface_zwlr_layer_shell_v1_api API
* See @ref iface_zwlr_layer_shell_v1.
*/
/**
* @defgroup iface_zwlr_layer_shell_v1 The zwlr_layer_shell_v1 interface
*
* Clients can use this interface to assign the surface_layer role to
* wl_surfaces. Such surfaces are assigned to a "layer" of the output and
* rendered with a defined z-depth respective to each other. They may also be
* anchored to the edges and corners of a screen and specify input handling
* semantics. This interface should be suitable for the implementation of
* many desktop shell components, and a broad number of other applications
* that interact with the desktop.
*/
extern const struct wl_interface zwlr_layer_shell_v1_interface;
/**
* @page page_iface_zwlr_layer_surface_v1 zwlr_layer_surface_v1
* @section page_iface_zwlr_layer_surface_v1_desc Description
*
* An interface that may be implemented by a wl_surface, for surfaces that
* are designed to be rendered as a layer of a stacked desktop-like
* environment.
*
* Layer surface state (size, anchor, exclusive zone, margin, interactivity)
* is double-buffered, and will be applied at the time wl_surface.commit of
* the corresponding wl_surface is called.
* @section page_iface_zwlr_layer_surface_v1_api API
* See @ref iface_zwlr_layer_surface_v1.
*/
/**
* @defgroup iface_zwlr_layer_surface_v1 The zwlr_layer_surface_v1 interface
*
* An interface that may be implemented by a wl_surface, for surfaces that
* are designed to be rendered as a layer of a stacked desktop-like
* environment.
*
* Layer surface state (size, anchor, exclusive zone, margin, interactivity)
* is double-buffered, and will be applied at the time wl_surface.commit of
* the corresponding wl_surface is called.
*/
extern const struct wl_interface zwlr_layer_surface_v1_interface;
#ifndef ZWLR_LAYER_SHELL_V1_ERROR_ENUM
#define ZWLR_LAYER_SHELL_V1_ERROR_ENUM
enum zwlr_layer_shell_v1_error {
/**
* wl_surface has another role
*/
ZWLR_LAYER_SHELL_V1_ERROR_ROLE = 0,
/**
* layer value is invalid
*/
ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER = 1,
/**
* wl_surface has a buffer attached or committed
*/
ZWLR_LAYER_SHELL_V1_ERROR_ALREADY_CONSTRUCTED = 2,
};
#endif /* ZWLR_LAYER_SHELL_V1_ERROR_ENUM */
#ifndef ZWLR_LAYER_SHELL_V1_LAYER_ENUM
#define ZWLR_LAYER_SHELL_V1_LAYER_ENUM
/**
* @ingroup iface_zwlr_layer_shell_v1
* available layers for surfaces
*
* These values indicate which layers a surface can be rendered in. They
* are ordered by z depth, bottom-most first. Traditional shell surfaces
* will typically be rendered between the bottom and top layers.
* Fullscreen shell surfaces are typically rendered at the top layer.
* Multiple surfaces can share a single layer, and ordering within a
* single layer is undefined.
*/
enum zwlr_layer_shell_v1_layer {
ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND = 0,
ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM = 1,
ZWLR_LAYER_SHELL_V1_LAYER_TOP = 2,
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY = 3,
};
#endif /* ZWLR_LAYER_SHELL_V1_LAYER_ENUM */
#define ZWLR_LAYER_SHELL_V1_GET_LAYER_SURFACE 0
/**
* @ingroup iface_zwlr_layer_shell_v1
*/
#define ZWLR_LAYER_SHELL_V1_GET_LAYER_SURFACE_SINCE_VERSION 1
/** @ingroup iface_zwlr_layer_shell_v1 */
static inline void
zwlr_layer_shell_v1_set_user_data(struct zwlr_layer_shell_v1 *zwlr_layer_shell_v1, void *user_data)
{
wl_proxy_set_user_data((struct wl_proxy *) zwlr_layer_shell_v1, user_data);
}
/** @ingroup iface_zwlr_layer_shell_v1 */
static inline void *
zwlr_layer_shell_v1_get_user_data(struct zwlr_layer_shell_v1 *zwlr_layer_shell_v1)
{
return wl_proxy_get_user_data((struct wl_proxy *) zwlr_layer_shell_v1);
}
static inline uint32_t
zwlr_layer_shell_v1_get_version(struct zwlr_layer_shell_v1 *zwlr_layer_shell_v1)
{
return wl_proxy_get_version((struct wl_proxy *) zwlr_layer_shell_v1);
}
/** @ingroup iface_zwlr_layer_shell_v1 */
static inline void
zwlr_layer_shell_v1_destroy(struct zwlr_layer_shell_v1 *zwlr_layer_shell_v1)
{
wl_proxy_destroy((struct wl_proxy *) zwlr_layer_shell_v1);
}
/**
* @ingroup iface_zwlr_layer_shell_v1
*
* Create a layer surface for an existing surface. This assigns the role of
* layer_surface, or raises a protocol error if another role is already
* assigned.
*
* Creating a layer surface from a wl_surface which has a buffer attached
* or committed is a client error, and any attempts by a client to attach
* or manipulate a buffer prior to the first layer_surface.configure call
* must also be treated as errors.
*
* You may pass NULL for output to allow the compositor to decide which
* output to use. Generally this will be the one that the user most
* recently interacted with.
*
* Clients can specify a namespace that defines the purpose of the layer
* surface.
*/
static inline struct zwlr_layer_surface_v1 *
zwlr_layer_shell_v1_get_layer_surface(struct zwlr_layer_shell_v1 *zwlr_layer_shell_v1, struct wl_surface *surface, struct wl_output *output, uint32_t layer, const char *namespace)
{
struct wl_proxy *id;
id = wl_proxy_marshal_constructor((struct wl_proxy *) zwlr_layer_shell_v1,
ZWLR_LAYER_SHELL_V1_GET_LAYER_SURFACE, &zwlr_layer_surface_v1_interface, NULL, surface, output, layer, namespace);
return (struct zwlr_layer_surface_v1 *) id;
}
#ifndef ZWLR_LAYER_SURFACE_V1_ERROR_ENUM
#define ZWLR_LAYER_SURFACE_V1_ERROR_ENUM
enum zwlr_layer_surface_v1_error {
/**
* provided surface state is invalid
*/
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SURFACE_STATE = 0,
/**
* size is invalid
*/
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE = 1,
/**
* anchor bitfield is invalid
*/
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_ANCHOR = 2,
};
#endif /* ZWLR_LAYER_SURFACE_V1_ERROR_ENUM */
#ifndef ZWLR_LAYER_SURFACE_V1_ANCHOR_ENUM
#define ZWLR_LAYER_SURFACE_V1_ANCHOR_ENUM
enum zwlr_layer_surface_v1_anchor {
/**
* the top edge of the anchor rectangle
*/
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP = 1,
/**
* the bottom edge of the anchor rectangle
*/
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM = 2,
/**
* the left edge of the anchor rectangle
*/
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT = 4,
/**
* the right edge of the anchor rectangle
*/
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT = 8,
};
#endif /* ZWLR_LAYER_SURFACE_V1_ANCHOR_ENUM */
/**
* @ingroup iface_zwlr_layer_surface_v1
* @struct zwlr_layer_surface_v1_listener
*/
struct zwlr_layer_surface_v1_listener {
/**
* suggest a surface change
*
* The configure event asks the client to resize its surface.
*
* Clients should arrange their surface for the new states, and
* then send an ack_configure request with the serial sent in this
* configure event at some point before committing the new surface.
*
* The client is free to dismiss all but the last configure event
* it received.
*
* The width and height arguments specify the size of the window in
* surface-local coordinates.
*
* The size is a hint, in the sense that the client is free to
* ignore it if it doesn't resize, pick a smaller size (to satisfy
* aspect ratio or resize in steps of NxM pixels). If the client
* picks a smaller size and is anchored to two opposite anchors
* (e.g. 'top' and 'bottom'), the surface will be centered on this
* axis.
*
* If the width or height arguments are zero, it means the client
* should decide its own window dimension.
*/
void (*configure)(void *data,
struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1,
uint32_t serial,
uint32_t width,
uint32_t height);
/**
* surface should be closed
*
* The closed event is sent by the compositor when the surface
* will no longer be shown. The output may have been destroyed or
* the user may have asked for it to be removed. Further changes to
* the surface will be ignored. The client should destroy the
* resource after receiving this event, and create a new surface if
* they so choose.
*/
void (*closed)(void *data,
struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1);
};
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
static inline int
zwlr_layer_surface_v1_add_listener(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1,
const struct zwlr_layer_surface_v1_listener *listener, void *data)
{
return wl_proxy_add_listener((struct wl_proxy *) zwlr_layer_surface_v1,
(void (**)(void)) listener, data);
}
#define ZWLR_LAYER_SURFACE_V1_SET_SIZE 0
#define ZWLR_LAYER_SURFACE_V1_SET_ANCHOR 1
#define ZWLR_LAYER_SURFACE_V1_SET_EXCLUSIVE_ZONE 2
#define ZWLR_LAYER_SURFACE_V1_SET_MARGIN 3
#define ZWLR_LAYER_SURFACE_V1_SET_KEYBOARD_INTERACTIVITY 4
#define ZWLR_LAYER_SURFACE_V1_GET_POPUP 5
#define ZWLR_LAYER_SURFACE_V1_ACK_CONFIGURE 6
#define ZWLR_LAYER_SURFACE_V1_DESTROY 7
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_CONFIGURE_SINCE_VERSION 1
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_CLOSED_SINCE_VERSION 1
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_SET_SIZE_SINCE_VERSION 1
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_SET_ANCHOR_SINCE_VERSION 1
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_SET_EXCLUSIVE_ZONE_SINCE_VERSION 1
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_SET_MARGIN_SINCE_VERSION 1
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_SET_KEYBOARD_INTERACTIVITY_SINCE_VERSION 1
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_GET_POPUP_SINCE_VERSION 1
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_ACK_CONFIGURE_SINCE_VERSION 1
/**
* @ingroup iface_zwlr_layer_surface_v1
*/
#define ZWLR_LAYER_SURFACE_V1_DESTROY_SINCE_VERSION 1
/** @ingroup iface_zwlr_layer_surface_v1 */
static inline void
zwlr_layer_surface_v1_set_user_data(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1, void *user_data)
{
wl_proxy_set_user_data((struct wl_proxy *) zwlr_layer_surface_v1, user_data);
}
/** @ingroup iface_zwlr_layer_surface_v1 */
static inline void *
zwlr_layer_surface_v1_get_user_data(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1)
{
return wl_proxy_get_user_data((struct wl_proxy *) zwlr_layer_surface_v1);
}
static inline uint32_t
zwlr_layer_surface_v1_get_version(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1)
{
return wl_proxy_get_version((struct wl_proxy *) zwlr_layer_surface_v1);
}
/**
* @ingroup iface_zwlr_layer_surface_v1
*
* Sets the size of the surface in surface-local coordinates. The
* compositor will display the surface centered with respect to its
* anchors.
*
* If you pass 0 for either value, the compositor will assign it and
* inform you of the assignment in the configure event. You must set your
* anchor to opposite edges in the dimensions you omit; not doing so is a
* protocol error. Both values are 0 by default.
*
* Size is double-buffered, see wl_surface.commit.
*/
static inline void
zwlr_layer_surface_v1_set_size(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1, uint32_t width, uint32_t height)
{
wl_proxy_marshal((struct wl_proxy *) zwlr_layer_surface_v1,
ZWLR_LAYER_SURFACE_V1_SET_SIZE, width, height);
}
/**
* @ingroup iface_zwlr_layer_surface_v1
*
* Requests that the compositor anchor the surface to the specified edges
* and corners. If two orthoginal edges are specified (e.g. 'top' and
* 'left'), then the anchor point will be the intersection of the edges
* (e.g. the top left corner of the output); otherwise the anchor point
* will be centered on that edge, or in the center if none is specified.
*
* Anchor is double-buffered, see wl_surface.commit.
*/
static inline void
zwlr_layer_surface_v1_set_anchor(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1, uint32_t anchor)
{
wl_proxy_marshal((struct wl_proxy *) zwlr_layer_surface_v1,
ZWLR_LAYER_SURFACE_V1_SET_ANCHOR, anchor);
}
/**
* @ingroup iface_zwlr_layer_surface_v1
*
* Requests that the compositor avoids occluding an area of the surface
* with other surfaces. The compositor's use of this information is
* implementation-dependent - do not assume that this region will not
* actually be occluded.
*
* A positive value is only meaningful if the surface is anchored to an
* edge, rather than a corner. The zone is the number of surface-local
* coordinates from the edge that are considered exclusive.
*
* Surfaces that do not wish to have an exclusive zone may instead specify
* how they should interact with surfaces that do. If set to zero, the
* surface indicates that it would like to be moved to avoid occluding
* surfaces with a positive excluzive zone. If set to -1, the surface
* indicates that it would not like to be moved to accomodate for other
* surfaces, and the compositor should extend it all the way to the edges
* it is anchored to.
*
* For example, a panel might set its exclusive zone to 10, so that
* maximized shell surfaces are not shown on top of it. A notification
* might set its exclusive zone to 0, so that it is moved to avoid
* occluding the panel, but shell surfaces are shown underneath it. A
* wallpaper or lock screen might set their exclusive zone to -1, so that
* they stretch below or over the panel.
*
* The default value is 0.
*
* Exclusive zone is double-buffered, see wl_surface.commit.
*/
static inline void
zwlr_layer_surface_v1_set_exclusive_zone(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1, int32_t zone)
{
wl_proxy_marshal((struct wl_proxy *) zwlr_layer_surface_v1,
ZWLR_LAYER_SURFACE_V1_SET_EXCLUSIVE_ZONE, zone);
}
/**
* @ingroup iface_zwlr_layer_surface_v1
*
* Requests that the surface be placed some distance away from the anchor
* point on the output, in surface-local coordinates. Setting this value
* for edges you are not anchored to has no effect.
*
* The exclusive zone includes the margin.
*
* Margin is double-buffered, see wl_surface.commit.
*/
static inline void
zwlr_layer_surface_v1_set_margin(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1, int32_t top, int32_t right, int32_t bottom, int32_t left)
{
wl_proxy_marshal((struct wl_proxy *) zwlr_layer_surface_v1,
ZWLR_LAYER_SURFACE_V1_SET_MARGIN, top, right, bottom, left);
}
/**
* @ingroup iface_zwlr_layer_surface_v1
*
* Set to 1 to request that the seat send keyboard events to this layer
* surface. For layers below the shell surface layer, the seat will use
* normal focus semantics. For layers above the shell surface layers, the
* seat will always give exclusive keyboard focus to the top-most layer
* which has keyboard interactivity set to true.
*
* Layer surfaces receive pointer, touch, and tablet events normally. If
* you do not want to receive them, set the input region on your surface
* to an empty region.
*
* Events is double-buffered, see wl_surface.commit.
*/
static inline void
zwlr_layer_surface_v1_set_keyboard_interactivity(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1, uint32_t keyboard_interactivity)
{
wl_proxy_marshal((struct wl_proxy *) zwlr_layer_surface_v1,
ZWLR_LAYER_SURFACE_V1_SET_KEYBOARD_INTERACTIVITY, keyboard_interactivity);
}
/**
* @ingroup iface_zwlr_layer_surface_v1
*
* This assigns an xdg_popup's parent to this layer_surface. This popup
* should have been created via xdg_surface::get_popup with the parent set
* to NULL, and this request must be invoked before committing the popup's
* initial state.
*
* See the documentation of xdg_popup for more details about what an
* xdg_popup is and how it is used.
*/
static inline void
zwlr_layer_surface_v1_get_popup(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1, struct xdg_popup *popup)
{
wl_proxy_marshal((struct wl_proxy *) zwlr_layer_surface_v1,
ZWLR_LAYER_SURFACE_V1_GET_POPUP, popup);
}
/**
* @ingroup iface_zwlr_layer_surface_v1
*
* When a configure event is received, if a client commits the
* surface in response to the configure event, then the client
* must make an ack_configure request sometime before the commit
* request, passing along the serial of the configure event.
*
* If the client receives multiple configure events before it
* can respond to one, it only has to ack the last configure event.
*
* A client is not required to commit immediately after sending
* an ack_configure request - it may even ack_configure several times
* before its next surface commit.
*
* A client may send multiple ack_configure requests before committing, but
* only the last request sent before a commit indicates which configure
* event the client really is responding to.
*/
static inline void
zwlr_layer_surface_v1_ack_configure(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1, uint32_t serial)
{
wl_proxy_marshal((struct wl_proxy *) zwlr_layer_surface_v1,
ZWLR_LAYER_SURFACE_V1_ACK_CONFIGURE, serial);
}
/**
* @ingroup iface_zwlr_layer_surface_v1
*
* This request destroys the layer surface.
*/
static inline void
zwlr_layer_surface_v1_destroy(struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1)
{
wl_proxy_marshal((struct wl_proxy *) zwlr_layer_surface_v1,
ZWLR_LAYER_SURFACE_V1_DESTROY);
wl_proxy_destroy((struct wl_proxy *) zwlr_layer_surface_v1);
}
#ifdef __cplusplus
}
#endif
#endif
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/inc/wofi.h 0000644 0000000 0000000 00000003140 00000000000 012517 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#ifndef WAIFU_H
#define WAIFU_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct cache_line {
char* line;
struct wl_list link;
};
void wofi_init(struct map* config);
char* wofi_parse_image_escapes(const char* text);
void wofi_write_cache(const gchar* mode, const gchar* cmd);
struct wl_list* wofi_read_cache(char* mode);
void wofi_insert_widget(char* mode, char** text, char* search_text, char** actions, size_t action_count);
bool wofi_allow_images();
bool wofi_allow_markup();
uint64_t wofi_get_image_size();
bool wofi_mod_shift();
bool wofi_mod_control();
void wofi_term_run(const char* cmd);
#endif
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/meson.build 0000644 0000000 0000000 00000001455 00000000000 013002 0 ustar 00 0000000 0000000 project('wofi', 'c', version : 'v1.0', default_options : ['buildtype=release', 'warning_level=2'])
cc = meson.get_compiler('c')
inc = include_directories('inc')
gtk = dependency('gtk+-3.0')
gio = dependency('gio-unix-2.0')
threads = dependency('threads')
wayland = dependency('wayland-client')
dl = cc.find_library('dl')
add_project_arguments('-D_GNU_SOURCE', '-DVERSION="' + meson.project_version() + '"', language : 'c')
add_project_link_arguments('-rdynamic', language : 'c')
executable('wofi',
'src/config.c',
'src/main.c',
'src/map.c',
'src/property_box.c',
'src/utils.c',
'src/wofi.c',
'modes/dmenu.c',
'modes/drun.c',
'modes/run.c',
'proto/wlr-layer-shell-unstable-v1-protocol.c',
'proto/xdg-shell-protocol.c',
include_directories : inc,
dependencies : [gtk, gio, threads, wayland, dl], install : true)
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/modes/dmenu.c 0000644 0000000 0000000 00000004142 00000000000 013217 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#include
#define MODE "dmenu"
static const char* arg_names[] = {"parse_action"};
static bool parse_action;
void wofi_dmenu_init(struct map* config) {
parse_action = strcmp(config_get(config, "parse_action", "false"), "true") == 0;
struct map* cached = map_init();
struct wl_list* cache = wofi_read_cache(MODE);
struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) {
wofi_insert_widget(MODE, &node->line, node->line, &node->line, 1);
map_put(cached, node->line, "true");
free(node->line);
wl_list_remove(&node->link);
free(node);
}
free(cache);
char* line = NULL;
size_t size = 0;
while(getline(&line, &size, stdin) != -1) {
char* lf = strchr(line, '\n');
if(lf != NULL) {
*lf = 0;
}
if(map_contains(cached, line)) {
continue;
}
wofi_insert_widget(MODE, &line, line, &line, 1);
}
free(line);
map_free(cached);
}
void wofi_dmenu_exec(const gchar* cmd) {
char* action = strdup(cmd);
if(parse_action) {
if(wofi_allow_images()) {
free(action);
action = wofi_parse_image_escapes(cmd);
}
if(wofi_allow_markup()) {
char* out;
pango_parse_markup(action, -1, 0, NULL, &out, NULL, NULL);
free(action);
action = out;
}
}
wofi_write_cache(MODE, cmd);
printf("%s\n", action);
free(action);
exit(0);
}
const char** wofi_dmenu_get_arg_names() {
return arg_names;
}
size_t wofi_dmenu_get_arg_count() {
return sizeof(arg_names) / sizeof(char*);
}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/modes/drun.c 0000644 0000000 0000000 00000017004 00000000000 013060 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#include
#define MODE "drun"
static char* get_text(char* file, char* action) {
GDesktopAppInfo* info = g_desktop_app_info_new_from_filename(file);
if(info == NULL || g_desktop_app_info_get_is_hidden(info) || g_desktop_app_info_get_nodisplay(info)) {
return NULL;
}
const char* name;
if(action == NULL) {
name = g_app_info_get_display_name(G_APP_INFO(info));
} else {
name = g_desktop_app_info_get_action_name(info, action);
}
if(name == NULL) {
return NULL;
}
if(wofi_allow_images()) {
GIcon* icon = g_app_info_get_icon(G_APP_INFO(info));
if(G_IS_FILE_ICON(icon)) {
GFile* file = g_file_icon_get_file(G_FILE_ICON(icon));
char* path = g_file_get_path(file);
return utils_concat(4, "img:", path, ":text:", name);
} else {
GtkIconTheme* theme = gtk_icon_theme_get_default();
GtkIconInfo* info = NULL;
if(icon != NULL) {
const gchar* const* icon_names = g_themed_icon_get_names(G_THEMED_ICON(icon));
info = gtk_icon_theme_choose_icon(theme, (const gchar**) icon_names, wofi_get_image_size(), 0);
}
if(info == NULL) {
info = gtk_icon_theme_lookup_icon(theme, "application-x-executable", wofi_get_image_size(), 0);
}
const gchar* icon_path = gtk_icon_info_get_filename(info);
return utils_concat(4, "img:", icon_path, ":text:", name);
}
} else {
return strdup(name);
}
}
static char* get_search_text(char* file) {
GDesktopAppInfo* info = g_desktop_app_info_new_from_filename(file);
const char* name = g_app_info_get_display_name(G_APP_INFO(info));
const char* exec = g_app_info_get_executable(G_APP_INFO(info));
const char* description = g_app_info_get_description(G_APP_INFO(info));
const char* categories = g_desktop_app_info_get_categories(info);
const char* const* keywords = g_desktop_app_info_get_keywords(info);
return utils_concat(6, name, file, exec == NULL ? "" : exec, description == NULL ? "" : description, categories == NULL ? "" : categories, keywords == NULL ? (const char* const*) "" : keywords);
}
static const gchar* const* get_actions(char* file, size_t* action_count) {
*action_count = 0;
GDesktopAppInfo* info = g_desktop_app_info_new_from_filename(file);
if(info == NULL) {
return NULL;
}
const gchar* const* actions = g_desktop_app_info_list_actions(info);
if(actions[0] == NULL) {
return NULL;
}
for(; actions[*action_count] != NULL; ++*action_count);
return actions;
}
static char** get_action_text(char* file, size_t* text_count) {
*text_count = 0;
char* tmp = get_text(file, NULL);
if(tmp == NULL) {
return NULL;
}
const gchar* const* action_names = get_actions(file, text_count);
++*text_count;
char** text = malloc(*text_count * sizeof(char*));
text[0] = tmp;
for(size_t count = 1; count < *text_count; ++count) {
text[count] = get_text(file, (gchar*) action_names[count - 1]);
}
return text;
}
static char** get_action_actions(char* file, size_t* action_count) {
*action_count = 0;
char* tmp = strdup(file);
if(tmp == NULL) {
return NULL;
}
const gchar* const* action_names = get_actions(file, action_count);
++*action_count;
char** actions = malloc(*action_count * sizeof(char*));
actions[0] = tmp;
for(size_t count = 1; count < *action_count; ++count) {
actions[count] = utils_concat(3, file, " ", (gchar*) action_names[count - 1]);
}
return actions;
}
static void insert_dir(char* app_dir, struct map* cached, struct map* entries) {
DIR* dir = opendir(app_dir);
if(dir == NULL) {
return;
}
struct dirent* entry;
while((entry = readdir(dir)) != NULL) {
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
char* full_path = utils_concat(3, app_dir, "/", entry->d_name);
struct stat info;
stat(full_path, &info);
if(S_ISDIR(info.st_mode)) {
insert_dir(full_path, cached, entries);
free(full_path);
continue;
}
if(map_contains(cached, full_path)) {
free(full_path);
continue;
}
if(map_contains(entries, entry->d_name)) {
free(full_path);
continue;
}
size_t action_count;
char** text = get_action_text(full_path, &action_count);
map_put(entries, entry->d_name, "true");
if(text == NULL) {
free(full_path);
continue;
}
char** actions = get_action_actions(full_path, &action_count);
char* search_text = get_search_text(full_path);
wofi_insert_widget(MODE, text, search_text, actions, action_count);
for(size_t count = 0; count < action_count; ++count) {
free(actions[count]);
free(text[count]);
}
free(text);
free(actions);
free(search_text);
free(full_path);
}
closedir(dir);
}
void wofi_drun_init() {
struct map* cached = map_init();
struct map* entries = map_init();
struct wl_list* cache = wofi_read_cache(MODE);
struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) {
size_t action_count;
char** text = get_action_text(node->line, &action_count);
if(text == NULL) {
goto cache_cont;
}
char** actions = get_action_actions(node->line, &action_count);
char* search_text = get_search_text(node->line);
wofi_insert_widget(MODE, text, search_text, actions, action_count);
map_put(cached, node->line, "true");
free(search_text);
for(size_t count = 0; count < action_count; ++count) {
free(text[count]);
free(actions[count]);
}
free(text);
free(actions);
cache_cont:
free(node->line);
wl_list_remove(&node->link);
free(node);
}
free(cache);
char* data_home = getenv("XDG_DATA_HOME");
if(data_home == NULL) {
data_home = utils_concat(2, getenv("HOME"), "/.local/share");
} else {
data_home = strdup(data_home);
}
char* data_dirs = getenv("XDG_DATA_DIRS");
if(data_dirs == NULL) {
data_dirs = "/usr/local/share:/usr/share";
}
char* dirs = utils_concat(3, data_home, ":", data_dirs);
free(data_home);
char* save_ptr;
char* str = strtok_r(dirs, ":", &save_ptr);
do {
char* app_dir = utils_concat(2, str, "/applications");
insert_dir(app_dir, cached, entries);
free(app_dir);
} while((str = strtok_r(NULL, ":", &save_ptr)) != NULL);
free(dirs);
map_free(cached);
map_free(entries);
}
static void launch_done(GObject* obj, GAsyncResult* result, gpointer data) {
if(g_app_info_launch_uris_finish(G_APP_INFO(obj), result, NULL)) {
exit(0);
} else {
char* cmd = data;
fprintf(stderr, "%s cannot be executed\n", cmd);
exit(1);
}
}
void wofi_drun_exec(const gchar* cmd) {
GDesktopAppInfo* info = g_desktop_app_info_new_from_filename(cmd);
if(G_IS_DESKTOP_APP_INFO(info)) {
wofi_write_cache(MODE, cmd);
g_app_info_launch_uris_async(G_APP_INFO(info), NULL, NULL, NULL, launch_done, (gchar*) cmd);
} else if(strrchr(cmd, ' ') != NULL) {
char* space = strrchr(cmd, ' ');
*space = 0;
wofi_write_cache(MODE, cmd);
info = g_desktop_app_info_new_from_filename(cmd);
char* action = space + 1;
g_desktop_app_info_launch_action(info, action, NULL);
utils_sleep_millis(500);
exit(0);
} else {
fprintf(stderr, "%s cannot be executed\n", cmd);
exit(1);
}
}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/modes/run.c 0000644 0000000 0000000 00000006565 00000000000 012726 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#include
#define MODE "run"
static const char* arg_names[] = {"always_parse_args", "show_all"};
static bool always_parse_args;
static bool show_all;
void wofi_run_init(struct map* config) {
always_parse_args = strcmp(config_get(config, arg_names[0], "false"), "true") == 0;
show_all = strcmp(config_get(config, arg_names[1], "true"), "true") == 0;
struct map* cached = map_init();
struct wl_list* cache = wofi_read_cache(MODE);
struct map* entries = map_init();
struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) {
char* text;
char* final_slash = strrchr(node->line, '/');
if(final_slash == NULL) {
text = node->line;
} else {
text = final_slash + 1;
}
wofi_insert_widget(MODE, &text, text, &node->line, 1);
map_put(cached, node->line, "true");
map_put(entries, text, "true");
free(node->line);
wl_list_remove(&node->link);
free(node);
}
free(cache);
char* path = strdup(getenv("PATH"));
char* save_ptr;
char* str = strtok_r(path, ":", &save_ptr);
do {
DIR* dir = opendir(str);
if(dir == NULL) {
continue;
}
struct dirent* entry;
while((entry = readdir(dir)) != NULL) {
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
char* full_path = utils_concat(3, str, "/", entry->d_name);
struct stat info;
stat(full_path, &info);
if(access(full_path, X_OK) == 0 && S_ISREG(info.st_mode) && !map_contains(cached, full_path) && (show_all || !map_contains(entries, entry->d_name))) {
char* text = strdup(entry->d_name);
map_put(entries, text, "true");
wofi_insert_widget(MODE, &text, text, &full_path, 1);
free(text);
}
free(full_path);
}
closedir(dir);
} while((str = strtok_r(NULL, ":", &save_ptr)) != NULL);
free(path);
map_free(cached);
map_free(entries);
}
void wofi_run_exec(const gchar* cmd) {
if(wofi_mod_shift()) {
wofi_write_cache(MODE, cmd);
wofi_term_run(cmd);
}
if(wofi_mod_control() || always_parse_args) {
char* tmp = strdup(cmd);
size_t space_count = 2;
char* space;
while((space = strchr(tmp, ' ')) != NULL) {
++space_count;
*space = '\n';
}
char** args = malloc(space_count * sizeof(char*));
char* save_ptr;
char* str = strtok_r(tmp, "\n", &save_ptr);
size_t count = 0;
do {
args[count++] = str;
} while((str = strtok_r(NULL, "\n", &save_ptr)) != NULL);
args[space_count - 1] = NULL;
wofi_write_cache(MODE, tmp);
execvp(tmp, args);
} else {
wofi_write_cache(MODE, cmd);
execl(cmd, cmd, NULL);
}
fprintf(stderr, "%s cannot be executed\n", cmd);
exit(errno);
}
const char** wofi_run_get_arg_names() {
return arg_names;
}
size_t wofi_run_get_arg_count() {
return sizeof(arg_names) / sizeof(char*);
}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/proto/wlr-layer-shell-unstable-v1-protocol.c 0000644 0000000 0000000 00000005617 00000000000 021174 0 ustar 00 0000000 0000000 /* Generated by wayland-scanner 1.16.0 */
/*
* Copyright © 2017 Drew DeVault
*
* Permission to use, copy, modify, distribute, and sell this
* software and its documentation for any purpose is hereby granted
* without fee, provided that the above copyright notice appear in
* all copies and that both that copyright notice and this permission
* notice appear in supporting documentation, and that the name of
* the copyright holders not be used in advertising or publicity
* pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
* THIS SOFTWARE.
*/
#include
#include
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_output_interface;
extern const struct wl_interface wl_surface_interface;
extern const struct wl_interface xdg_popup_interface;
extern const struct wl_interface zwlr_layer_surface_v1_interface;
static const struct wl_interface *types[] = {
NULL,
NULL,
NULL,
NULL,
&zwlr_layer_surface_v1_interface,
&wl_surface_interface,
&wl_output_interface,
NULL,
NULL,
&xdg_popup_interface,
};
static const struct wl_message zwlr_layer_shell_v1_requests[] = {
{ "get_layer_surface", "no?ous", types + 4 },
};
WL_PRIVATE const struct wl_interface zwlr_layer_shell_v1_interface = {
"zwlr_layer_shell_v1", 1,
1, zwlr_layer_shell_v1_requests,
0, NULL,
};
static const struct wl_message zwlr_layer_surface_v1_requests[] = {
{ "set_size", "uu", types + 0 },
{ "set_anchor", "u", types + 0 },
{ "set_exclusive_zone", "i", types + 0 },
{ "set_margin", "iiii", types + 0 },
{ "set_keyboard_interactivity", "u", types + 0 },
{ "get_popup", "o", types + 9 },
{ "ack_configure", "u", types + 0 },
{ "destroy", "", types + 0 },
};
static const struct wl_message zwlr_layer_surface_v1_events[] = {
{ "configure", "uuu", types + 0 },
{ "closed", "", types + 0 },
};
WL_PRIVATE const struct wl_interface zwlr_layer_surface_v1_interface = {
"zwlr_layer_surface_v1", 1,
8, zwlr_layer_surface_v1_requests,
2, zwlr_layer_surface_v1_events,
};
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/proto/xdg-shell-protocol.c 0000644 0000000 0000000 00000012115 00000000000 015670 0 ustar 00 0000000 0000000 /* Generated by wayland-scanner 1.16.0 */
/*
* Copyright © 2008-2013 Kristian Høgsberg
* Copyright © 2013 Rafael Antognolli
* Copyright © 2013 Jasper St. Pierre
* Copyright © 2010-2013 Intel Corporation
* Copyright © 2015-2017 Samsung Electronics Co., Ltd
* Copyright © 2015-2017 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include
#include
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_output_interface;
extern const struct wl_interface wl_seat_interface;
extern const struct wl_interface wl_surface_interface;
extern const struct wl_interface xdg_popup_interface;
extern const struct wl_interface xdg_positioner_interface;
extern const struct wl_interface xdg_surface_interface;
extern const struct wl_interface xdg_toplevel_interface;
static const struct wl_interface *types[] = {
NULL,
NULL,
NULL,
NULL,
&xdg_positioner_interface,
&xdg_surface_interface,
&wl_surface_interface,
&xdg_toplevel_interface,
&xdg_popup_interface,
&xdg_surface_interface,
&xdg_positioner_interface,
&xdg_toplevel_interface,
&wl_seat_interface,
NULL,
NULL,
NULL,
&wl_seat_interface,
NULL,
&wl_seat_interface,
NULL,
NULL,
&wl_output_interface,
&wl_seat_interface,
NULL,
};
static const struct wl_message xdg_wm_base_requests[] = {
{ "destroy", "", types + 0 },
{ "create_positioner", "n", types + 4 },
{ "get_xdg_surface", "no", types + 5 },
{ "pong", "u", types + 0 },
};
static const struct wl_message xdg_wm_base_events[] = {
{ "ping", "u", types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_wm_base_interface = {
"xdg_wm_base", 2,
4, xdg_wm_base_requests,
1, xdg_wm_base_events,
};
static const struct wl_message xdg_positioner_requests[] = {
{ "destroy", "", types + 0 },
{ "set_size", "ii", types + 0 },
{ "set_anchor_rect", "iiii", types + 0 },
{ "set_anchor", "u", types + 0 },
{ "set_gravity", "u", types + 0 },
{ "set_constraint_adjustment", "u", types + 0 },
{ "set_offset", "ii", types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_positioner_interface = {
"xdg_positioner", 2,
7, xdg_positioner_requests,
0, NULL,
};
static const struct wl_message xdg_surface_requests[] = {
{ "destroy", "", types + 0 },
{ "get_toplevel", "n", types + 7 },
{ "get_popup", "n?oo", types + 8 },
{ "set_window_geometry", "iiii", types + 0 },
{ "ack_configure", "u", types + 0 },
};
static const struct wl_message xdg_surface_events[] = {
{ "configure", "u", types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_surface_interface = {
"xdg_surface", 2,
5, xdg_surface_requests,
1, xdg_surface_events,
};
static const struct wl_message xdg_toplevel_requests[] = {
{ "destroy", "", types + 0 },
{ "set_parent", "?o", types + 11 },
{ "set_title", "s", types + 0 },
{ "set_app_id", "s", types + 0 },
{ "show_window_menu", "ouii", types + 12 },
{ "move", "ou", types + 16 },
{ "resize", "ouu", types + 18 },
{ "set_max_size", "ii", types + 0 },
{ "set_min_size", "ii", types + 0 },
{ "set_maximized", "", types + 0 },
{ "unset_maximized", "", types + 0 },
{ "set_fullscreen", "?o", types + 21 },
{ "unset_fullscreen", "", types + 0 },
{ "set_minimized", "", types + 0 },
};
static const struct wl_message xdg_toplevel_events[] = {
{ "configure", "iia", types + 0 },
{ "close", "", types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_toplevel_interface = {
"xdg_toplevel", 2,
14, xdg_toplevel_requests,
2, xdg_toplevel_events,
};
static const struct wl_message xdg_popup_requests[] = {
{ "destroy", "", types + 0 },
{ "grab", "ou", types + 22 },
};
static const struct wl_message xdg_popup_events[] = {
{ "configure", "iiii", types + 0 },
{ "popup_done", "", types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_popup_interface = {
"xdg_popup", 2,
2, xdg_popup_requests,
2, xdg_popup_events,
};
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/src/config.c 0000644 0000000 0000000 00000004542 00000000000 013040 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#include
void config_load(struct map* map, const char* config) {
FILE* file = fopen(config, "r");
char* line = NULL;
size_t size = 0;
while(getline(&line, &size, file) != -1) {
char* hash = strchr(line, '#');
if(hash != NULL) {
if(hash == line || *(hash - 1) != '\\') {
*hash = 0;
}
}
char* backslash = strchr(line, '\\');
size_t backslash_count = 0;
while(backslash != NULL) {
++backslash_count;
backslash = strchr(backslash + 1, '\\');
}
char* new_line = calloc(1, size - backslash_count);
size_t line_size = strlen(line);
size_t new_line_count = 0;
for(size_t count = 0; count < line_size; ++count) {
if(line[count] == '\\') {
continue;
}
new_line[new_line_count++] = line[count];
}
free(line);
line = new_line;
char* equals = strchr(line, '=');
if(equals == NULL) {
continue;
}
*equals = 0;
char* key = equals - 1;
while(*key == ' ') {
--key;
}
*(key + 1) = 0;
char* value = equals + 1;
while(*value == ' ') {
++value;
}
size_t len = strlen(value);
*(value + len - 1) = 0;
map_put(map, line, value);
}
free(line);
fclose(file);
}
char* config_get(struct map* config, const char* key, char* def_opt) {
char* opt = map_get(config, key);
if(opt == NULL) {
opt = def_opt;
}
return opt;
}
uint8_t config_get_mnemonic(struct map* config, const char* key, char* def_opt, uint8_t num_choices, ...) {
char* opt = config_get(config, key, def_opt);
va_list ap;
va_start(ap, num_choices);
uint8_t result = 0;
for(uint8_t i = 0; i < num_choices; i++) {
char* cmp_str = va_arg(ap, char*);
if (strcmp(opt, cmp_str) == 0) {
result = i;
break;
}
}
va_end(ap);
return result;
}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/src/main.c 0000644 0000000 0000000 00000033105 00000000000 012514 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static char* CONFIG_LOCATION;
static char* COLORS_LOCATION;
static struct map* config;
static char* config_path;
static char* stylesheet;
static char* color_path;
static char* get_exec_name(char* path) {
char* slash = strrchr(path, '/');
uint64_t offset;
if(slash == NULL) {
offset = 0;
} else {
offset = (slash - path) + 1;
}
return path + offset;
}
static void print_usage(char** argv) {
printf("%s [options]\n", get_exec_name(argv[0]));
printf("Options:\n");
printf("--help\t\t-h\tDisplays this help message\n");
printf("--fork\t\t-f\tForks the menu so you can close the terminal\n");
printf("--conf\t\t-c\tSelects a config file to use\n");
printf("--style\t\t-s\tSelects a stylesheet to use\n");
printf("--color\t\t-C\tSelects a colors file to use\n");
printf("--dmenu\t\t-d\tRuns in dmenu mode\n");
printf("--show\t\t-S\tSpecifies the mode to run in\n");
printf("--width\t\t-W\tSpecifies the surface width\n");
printf("--height\t-H\tSpecifies the surface height\n");
printf("--prompt\t-p\tPrompt to display\n");
printf("--xoffset\t-x\tThe x offset\n");
printf("--yoffset\t-y\tThe y offset\n");
printf("--normal-window\t-n\tRender to a normal window\n");
printf("--allow-images\t-I\tAllows images to be rendered\n");
printf("--allow-markup\t-m\tAllows pango markup\n");
printf("--cache-file\t-k\tSets the cache file to use\n");
printf("--term\t\t-t\tSpecifies the terminal to use when running in a term\n");
printf("--password\t-P\tRuns in password mode\n");
printf("--exec-search\t-e\tMakes enter always use the search contents not the first result\n");
printf("--hide-scroll\t-b\tHides the scroll bars\n");
printf("--matching\t-M\tSets the matching method, default is contains\n");
printf("--insensitive\t-i\tAllows case insensitive searching\n");
printf("--parse-search\t-q\tParses the search text removing image escapes and pango\n");
printf("--version\t-v\tPrints the version and then exits\n");
exit(0);
}
static void load_css() {
if(access(stylesheet, R_OK) == 0) {
FILE* file = fopen(stylesheet, "r");
fseek(file, 0, SEEK_END);
ssize_t size = ftell(file);
fseek(file, 0, SEEK_SET);
char* data = malloc(size + 1);
fread(data, 1, size, file);
fclose(file);
data[size] = 0;
struct wl_list lines;
struct node {
char* line;
struct wl_list link;
};
wl_list_init(&lines);
if(access(color_path, R_OK) == 0) {
file = fopen(color_path, "r");
char* line = NULL;
size_t line_size = 0;
ssize_t line_l = 0;
while((line_l = getline(&line, &line_size, file)) != -1) {
struct node* entry = malloc(sizeof(struct node));
line[line_l - 1] = 0;
entry->line = malloc(line_l + 1);
strcpy(entry->line, line);
wl_list_insert(&lines, &entry->link);
}
fclose(file);
free(line);
}
ssize_t count = wl_list_length(&lines) - 1;
if(count > 99) {
fprintf(stderr, "Woah there that's a lot of colors. Try having no more than 99, thanks\n");
exit(1);
}
struct node* node;
wl_list_for_each(node, &lines, link) {
//Do --wofi-color replace
const char* color = node->line;
const char* wofi_color = "--wofi-color";
char count_str[3];
snprintf(count_str, 3, "%zu", count--);
char* needle = utils_concat(2, wofi_color, count_str);
size_t color_len = strlen(color);
size_t needle_len = strlen(needle);
if(color_len > needle_len) {
free(needle);
fprintf(stderr, "What color format is this, try #FFFFFF, kthxbi\n");
continue;
}
char* replace = strstr(data, needle);
while(replace != NULL) {
memcpy(replace, color, color_len);
memset(replace + color_len, ' ', needle_len - color_len);
replace = strstr(data, needle);
}
free(needle);
//Do --wofi-rgb-color replace
if(color_len < 7) {
fprintf(stderr, "What color format is this, try #FFFFFF, kthxbi\n");
continue;
}
const char* wofi_rgb_color = "--wofi-rgb-color";
needle = utils_concat(2, wofi_rgb_color, count_str);
needle_len = strlen(needle);
replace = strstr(data, needle);
while(replace != NULL) {
char r[3];
char g[3];
char b[3];
memcpy(r, color + 1, 2);
memcpy(g, color + 3, 2);
memcpy(b, color + 5, 2);
r[2] = 0;
g[2] = 0;
b[2] = 0;
char rgb[14];
snprintf(rgb, 14, "%ld, %ld, %ld", strtol(r, NULL, 16), strtol(g, NULL, 16), strtol(b, NULL, 16));
size_t rgb_len = strlen(rgb);
memcpy(replace, rgb, rgb_len);
memset(replace + rgb_len, ' ', needle_len - rgb_len);
replace = strstr(data, needle);
}
free(needle);
}
GtkCssProvider* css = gtk_css_provider_new();
gtk_css_provider_load_from_data(css, data, strlen(data), NULL);
free(data);
struct node* tmp;
wl_list_for_each_safe(node, tmp, &lines, link) {
free(node->line);
wl_list_remove(&node->link);
free(node);
}
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
}
int main(int argc, char** argv) {
const struct option opts[] = {
{
.name = "help",
.has_arg = no_argument,
.flag = NULL,
.val = 'h'
},
{
.name = "fork",
.has_arg = no_argument,
.flag = NULL,
.val = 'f'
},
{
.name = "conf",
.has_arg = required_argument,
.flag = NULL,
.val = 'c'
},
{
.name = "style",
.has_arg = required_argument,
.flag = NULL,
.val = 's'
},
{
.name = "color",
.has_arg = required_argument,
.flag = NULL,
.val = 'C'
},
{
.name = "dmenu",
.has_arg = no_argument,
.flag = NULL,
.val = 'd'
},
{
.name = "show",
.has_arg = required_argument,
.flag = NULL,
.val = 'S'
},
{
.name = "width",
.has_arg = required_argument,
.flag = NULL,
.val = 'W'
},
{
.name = "height",
.has_arg = required_argument,
.flag = NULL,
.val = 'H'
},
{
.name = "prompt",
.has_arg = required_argument,
.flag = NULL,
.val = 'p'
},
{
.name = "xoffset",
.has_arg = required_argument,
.flag = NULL,
.val = 'x'
},
{
.name = "yoffset",
.has_arg = required_argument,
.flag = NULL,
.val = 'y'
},
{
.name = "normal-window",
.has_arg = no_argument,
.flag = NULL,
.val = 'n'
},
{
.name = "allow-images",
.has_arg = no_argument,
.flag = NULL,
.val = 'I'
},
{
.name = "allow-markup",
.has_arg = no_argument,
.flag = NULL,
.val = 'm'
},
{
.name = "cache-file",
.has_arg = required_argument,
.flag = NULL,
.val = 'k'
},
{
.name = "term",
.has_arg = required_argument,
.flag = NULL,
.val = 't'
},
{
.name = "password",
.has_arg = optional_argument,
.flag = NULL,
.val = 'P'
},
{
.name = "exec-search",
.has_arg = no_argument,
.flag = NULL,
.val = 'e'
},
{
.name = "hide-scroll",
.has_arg = no_argument,
.flag = NULL,
.val = 'b'
},
{
.name = "matching",
.has_arg = required_argument,
.flag = NULL,
.val = 'M'
},
{
.name = "insensitive",
.has_arg = no_argument,
.flag = NULL,
.val = 'i'
},
{
.name = "parse-search",
.has_arg = no_argument,
.flag = NULL,
.val = 'q'
},
{
.name = "version",
.has_arg = no_argument,
.flag = NULL,
.val = 'v'
},
{
.name = NULL,
.has_arg = 0,
.flag = NULL,
.val = 0
}
};
const char* config_str = NULL;
char* style_str = NULL;
char* color_str = NULL;
char* mode = NULL;
char* prompt = NULL;
char* width = NULL;
char* height = NULL;
char* x = NULL;
char* y = NULL;
char* normal_window = NULL;
char* allow_images = NULL;
char* allow_markup = NULL;
char* cache_file = NULL;
char* terminal = NULL;
char* password_char = "false";
char* exec_search = NULL;
char* hide_scroll = NULL;
char* matching = NULL;
char* insensitive = NULL;
char* parse_search = NULL;
int opt;
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:iqv", opts, NULL)) != -1) {
switch(opt) {
case 'h':
print_usage(argv);
break;
case 'f':
if(fork() > 0) {
exit(0);
}
fclose(stdout);
fclose(stderr);
fclose(stdin);
break;
case 'c':
config_str = optarg;
break;
case 's':
style_str = optarg;
break;
case 'C':
color_str = optarg;
break;
case 'd':
mode = "dmenu";
break;
case 'S':
mode = optarg;
break;
case 'W':
width = optarg;
break;
case 'H':
height = optarg;
break;
case 'p':
prompt = optarg;
break;
case 'x':
x = optarg;
break;
case 'y':
y = optarg;
break;
case 'n':
normal_window = "true";
break;
case 'I':
allow_images = "true";
break;
case 'm':
allow_markup = "true";
break;
case 'k':
cache_file = optarg;
break;
case 't':
terminal = optarg;
break;
case 'P':
password_char = optarg;
break;
case 'e':
exec_search = "true";
break;
case 'b':
hide_scroll = "true";
break;
case 'M':
matching = optarg;
break;
case 'i':
insensitive = "true";
break;
case 'q':
parse_search = "true";
break;
case 'v':
printf(VERSION"\n");
exit(0);
break;
}
}
const char* home_dir = getenv("HOME");
const char* xdg_conf = getenv("XDG_CONFIG_HOME");
if(xdg_conf == NULL) {
CONFIG_LOCATION = utils_concat(2, home_dir, "/.config/wofi");
} else {
CONFIG_LOCATION = utils_concat(2, xdg_conf, "/wofi");
}
const char* xdg_cache = getenv("XDG_CACHE_HOME");
if(xdg_cache == NULL) {
COLORS_LOCATION = utils_concat(2, home_dir, "/.cache/wal/colors");
} else {
COLORS_LOCATION = utils_concat(2, xdg_cache, "/wal/colors");
}
config = map_init();
//Check if --conf was specified
if(config_str == NULL) {
const char* config_f = "/config";
config_path = utils_concat(2, CONFIG_LOCATION, config_f);
} else {
config_path = strdup(config_str);
}
if(access(config_path, R_OK) == 0) {
config_load(config, config_path);
}
free(config_path);
//Check if --style was specified
if(style_str == NULL) {
style_str = map_get(config, "stylesheet");
style_str = style_str == NULL ? map_get(config, "style") : style_str;
if(style_str == NULL) {
const char* style_f = "/style.css";
stylesheet = utils_concat(2, CONFIG_LOCATION, style_f);
} else {
if(style_str[0] == '/') {
stylesheet = strdup(style_str);
} else {
stylesheet = utils_concat(3, CONFIG_LOCATION, "/", style_str);
}
}
} else {
stylesheet = strdup(style_str);
}
//Check if --color was specified
if(color_str == NULL) {
color_str = map_get(config, "colors");
color_str = color_str == NULL ? map_get(config, "color") : color_str;
if(color_str == NULL) {
color_path = strdup(COLORS_LOCATION);
} else {
if(color_str[0] == '/') {
color_path = strdup(color_str);
} else {
color_path = utils_concat(3, CONFIG_LOCATION, "/", color_str);
}
}
} else {
color_path = strdup(color_str);
}
free(COLORS_LOCATION);
if(map_get(config, "show") != NULL) {
map_put(config, "mode", map_get(config, "show"));
}
if(strcmp(get_exec_name(argv[0]), "dmenu") == 0) {
map_put(config, "mode", "dmenu");
cache_file = "/dev/null";
} else if(mode != NULL) {
map_put(config, "mode", mode);
} else if(map_get(config, "mode") == NULL) {
fprintf(stderr, "I need a mode, please give me a mode, that's what --show is for\n");
exit(1);
}
map_put(config, "config_dir", CONFIG_LOCATION);
if(width != NULL) {
map_put(config, "width", width);
}
if(height != NULL) {
map_put(config, "height", height);
}
if(prompt != NULL) {
map_put(config, "prompt", prompt);
}
if(map_get(config, "xoffset") != NULL) {
map_put(config, "x", map_get(config, "xoffset"));
}
if(x != NULL) {
map_put(config, "x", x);
}
if(map_get(config, "yoffset") != NULL) {
map_put(config, "y", map_get(config, "yoffset"));
}
if(y != NULL) {
map_put(config, "y", y);
}
if(normal_window != NULL) {
map_put(config, "normal_window", normal_window);
}
if(allow_images != NULL) {
map_put(config, "allow_images", allow_images);
}
if(allow_markup != NULL) {
map_put(config, "allow_markup", allow_markup);
}
if(cache_file != NULL) {
map_put(config, "cache_file", cache_file);
}
if(terminal != NULL) {
map_put(config, "term", terminal);
}
if(map_get(config, "password") != NULL) {
map_put(config, "password_char", map_get(config, "password"));
}
if(password_char == NULL || (password_char != NULL && strcmp(password_char, "false") != 0)) {
if(password_char == NULL) {
password_char = "*";
}
map_put(config, "password_char", password_char);
}
if(exec_search != NULL) {
map_put(config, "exec_search", exec_search);
}
if(hide_scroll != NULL) {
map_put(config, "hide_scroll", hide_scroll);
}
if(matching != NULL) {
map_put(config, "matching", matching);
}
if(insensitive != NULL) {
map_put(config, "insensitive", insensitive);
}
if(parse_search != NULL) {
map_put(config, "parse_search", parse_search);
}
gtk_init(&argc, &argv);
load_css();
wofi_init(config);
gtk_main();
return 0;
}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/src/map.c 0000644 0000000 0000000 00000005745 00000000000 012356 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#include
struct map {
char* key;
void* value;
size_t size;
bool mman;
struct map* head, *left, *right;
};
struct map* map_init() {
struct map* map = calloc(1, sizeof(struct map));
map->head = map;
map->mman = true;
return map;
}
struct map* map_init_void() {
struct map* map = map_init();
map->mman = false;
return map;
}
void map_free(struct map* map) {
if(map->left != NULL) {
map_free(map->left);
}
if(map->right != NULL) {
map_free(map->right);
}
if(map->key != NULL) {
free(map->key);
}
if(map->value != NULL && map->head->mman) {
free(map->value);
}
free(map);
}
static void put(struct map* map, const char* key, void* value) {
if(map->key == NULL) {
map->key = strdup(key);
if(value != NULL && map->head->mman) {
map->value = strdup(value);
} else {
map->value = value;
}
++map->head->size;
} else if(strcmp(key, map->key) < 0) {
if(map->left == NULL) {
map->left = map_init();
map->left->head = map->head;
}
put(map->left, key, value);
} else if(strcmp(key, map->key) > 0) {
if(map->right == NULL) {
map->right = map_init();
map->right->head = map->head;
}
put(map->right, key, value);
} else {
if(map->value != NULL && map->head->mman) {
free(map->value);
}
if(value != NULL && map->head->mman) {
map->value = strdup(value);
} else {
map->value = value;
}
}
}
bool map_put(struct map* map, const char* key, char* value) {
if(map->head->mman) {
put(map, key, value);
return true;
} else {
fprintf(stderr, "This is an unmanaged map please use map_put_void\n");
return false;
}
}
bool map_put_void(struct map* map, const char* key, void* value) {
if(map->head->mman) {
fprintf(stderr, "This is an managed map please use map_put\n");
return false;
} else {
put(map, key, value);
return true;
}
}
void* map_get(struct map* map, const char* key) {
if(map->key == NULL) {
return NULL;
} else if(strcmp(key, map->key) < 0) {
if(map->left == NULL) {
return NULL;
}
return map_get(map->left, key);
} else if(strcmp(key, map->key) > 0) {
if(map->right == NULL) {
return NULL;
}
return map_get(map->right, key);
} else {
return map->value;
}
}
bool map_contains(struct map* map, const char* key) {
return map_get(map, key) != NULL;
}
size_t map_size(struct map* map) {
return map->size;
}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/src/property_box.c 0000644 0000000 0000000 00000004024 00000000000 014322 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#include
struct _WofiPropertyBox {
GtkBox super;
};
typedef struct {
struct map* properties;
} WofiPropertyBoxPrivate;
G_DEFINE_TYPE_WITH_PRIVATE(WofiPropertyBox, wofi_property_box, GTK_TYPE_BOX);
static void wofi_property_box_init(WofiPropertyBox* box) {
WofiPropertyBoxPrivate* this = wofi_property_box_get_instance_private(box);
this->properties = map_init();
}
static void finalize(GObject* obj) {
WofiPropertyBoxPrivate* this = wofi_property_box_get_instance_private(WOFI_PROPERTY_BOX(obj));
map_free(this->properties);
G_OBJECT_CLASS(wofi_property_box_parent_class)->finalize(obj);
}
static void wofi_property_box_class_init(WofiPropertyBoxClass* class) {
GObjectClass* g_class = G_OBJECT_CLASS(class);
g_class->finalize = finalize;
}
GtkWidget* wofi_property_box_new(GtkOrientation orientation, gint spacing) {
return g_object_new(WOFI_TYPE_PROPERTY_BOX, "orientation", orientation, "spacing", spacing, NULL);
}
void wofi_property_box_add_property(WofiPropertyBox* box, const gchar* key, gchar* value) {
WofiPropertyBoxPrivate* this = wofi_property_box_get_instance_private(box);
map_put(this->properties, key, value);
}
const gchar* wofi_property_box_get_property(WofiPropertyBox* box, const gchar* key) {
WofiPropertyBoxPrivate* this = wofi_property_box_get_instance_private(box);
return map_get(this->properties, key);
}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/src/utils.c 0000644 0000000 0000000 00000004557 00000000000 012741 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#include
time_t utils_get_time_millis() {
struct timeval time;
gettimeofday(&time, NULL);
return (time.tv_sec * 1000) + (time.tv_usec / 1000);
}
void utils_sleep_millis(time_t millis) {
struct timespec time;
time.tv_sec = millis / 1000;
time.tv_nsec = (millis % 1000) * pow(1000, 2);
nanosleep(&time, NULL);
}
char* utils_concat(size_t arg_count, ...) {
va_list args;
va_start(args, arg_count);
size_t buf_s = 1;
for(size_t count = 0; count < arg_count; ++count) {
buf_s += strlen(va_arg(args, char*));
}
va_end(args);
va_start(args, arg_count);
char* buffer = malloc(buf_s);
strcpy(buffer, va_arg(args, char*));
for(size_t count = 0; count < arg_count - 1; ++count) {
strcat(buffer, va_arg(args, char*));
}
va_end(args);
return buffer;
}
size_t utils_min(size_t n1, size_t n2) {
if(n1 < n2) {
return n1;
} else {
return n2;
}
}
size_t utils_min3(size_t n1, size_t n2, size_t n3) {
if(n1 < n2 && n1 < n3) {
return n1;
} else if(n2 < n1 && n2 < n3) {
return n2;
} else {
return n3;
}
}
size_t utils_distance(const char* str1, const char* str2) {
size_t str1_len = strlen(str1);
size_t str2_len = strlen(str2);
size_t arr[str1_len + 1][str2_len + 1];
arr[0][0] = 0;
for(size_t count = 1; count <= str1_len; ++count) {
arr[count][0] = count;
}
for(size_t count = 1; count <= str2_len; ++count) {
arr[0][count] = count;
}
uint8_t cost;
for(size_t c1 = 1; c1 <= str1_len; ++c1) {
for(size_t c2 = 1; c2 <= str2_len; ++c2) {
if(str1[c1 - 1] == str2[c2 - 1]) {
cost = 0;
} else {
cost = 1;
}
arr[c1][c2] = utils_min3(arr[c1 - 1][c2] + 1, arr[c1][c2 - 1] + 1, arr[c1 - 1][c2 - 1] + cost);
}
}
return arr[str1_len][str2_len];
}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 011453 x ustar 00 0000000 0000000 22 mtime=1576908116.0
wofi-v1.0/src/wofi.c 0000644 0000000 0000000 00000063735 00000000000 012550 0 ustar 00 0000000 0000000 /*
* Copyright (C) 2019 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wofi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wofi. If not, see .
*/
#include
static const char* terminals[] = {"kitty", "termite", "gnome-terminal", "weston-terminal"};
enum matching_mode {
MATCHING_MODE_CONTAINS,
MATCHING_MODE_FUZZY
};
static uint64_t width, height;
static int64_t x, y;
static struct zwlr_layer_shell_v1* shell;
static GtkWidget* window, *outer_box, *scroll, *entry, *inner_box, *previous_selection = NULL;
static const gchar* filter;
static char* mode = NULL;
static time_t filter_time;
static int64_t filter_rate;
static bool allow_images, allow_markup;
static uint64_t image_size;
static char* cache_file = NULL;
static char* config_dir;
static bool mod_shift;
static bool mod_ctrl;
static char* terminal;
static GtkOrientation outer_orientation;
static bool exec_search;
static struct map* modes;
static enum matching_mode matching;
static bool insensitive;
static bool parse_search;
static struct map* config;
struct node {
size_t action_count;
char* mode, **text, *search_text, **actions;
};
struct mode {
void (*mode_exec)(const gchar* cmd);
};
static void nop() {}
static void add_interface(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) {
(void) data;
if(strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
shell = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, version);
}
}
static void config_surface(void* data, struct zwlr_layer_surface_v1* surface, uint32_t serial, uint32_t _width, uint32_t _height) {
(void) data;
(void) _width;
(void) _height;
zwlr_layer_surface_v1_ack_configure(surface, serial);
zwlr_layer_surface_v1_set_size(surface, width, height);
zwlr_layer_surface_v1_set_keyboard_interactivity(surface, true);
if(x >= 0 && y >= 0) {
zwlr_layer_surface_v1_set_margin(surface, y, 0, 0, x);
zwlr_layer_surface_v1_set_anchor(surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
}
}
static void get_input(GtkSearchEntry* entry, gpointer data) {
(void) data;
if(utils_get_time_millis() - filter_time > filter_rate) {
filter = gtk_entry_get_text(GTK_ENTRY(entry));
filter_time = utils_get_time_millis();
gtk_flow_box_invalidate_filter(GTK_FLOW_BOX(inner_box));
gtk_flow_box_invalidate_sort(GTK_FLOW_BOX(inner_box));
}
}
static void get_search(GtkSearchEntry* entry, gpointer data) {
(void) data;
filter = gtk_entry_get_text(GTK_ENTRY(entry));
gtk_flow_box_invalidate_filter(GTK_FLOW_BOX(inner_box));
gtk_flow_box_invalidate_sort(GTK_FLOW_BOX(inner_box));
}
static char* parse_images(WofiPropertyBox* box, const char* text, bool create_widgets) {
char* ret = strdup("");
struct map* mode_map = map_init();
map_put(mode_map, "img", "true");
map_put(mode_map, "text", "true");
char* tmp = strdup(text);
struct wl_list modes;
struct node {
char* str;
struct wl_list link;
};
wl_list_init(&modes);
bool data = false;
char* save_ptr;
char* str = strtok_r(tmp, ":", &save_ptr);
do {
if(str == NULL) {
break;
}
if(map_contains(mode_map, str) || data) {
struct node* node = malloc(sizeof(struct node));
node->str = str;
wl_list_insert(&modes, &node->link);
data = !data;
}
} while((str = strtok_r(NULL, ":", &save_ptr)) != NULL);
char* tmp2 = strdup(text);
char* start = tmp2;
char* mode = NULL;
struct node* node = wl_container_of(modes.prev, node, link);
while(true) {
if(mode == NULL) {
if(start == NULL) {
break;
}
char* tmp_start = (start - tmp2) + tmp;
if(!wl_list_empty(&modes) && tmp_start == node->str) {
if(node->link.prev == &modes) {
break;
}
mode = node->str;
node = wl_container_of(node->link.prev, node, link);
str = node->str;
start = ((str + strlen(str) + 1) - tmp) + tmp2;
if(((start - tmp2) + text) > (text + strlen(text))) {
start = NULL;
}
if(node->link.prev != &modes) {
node = wl_container_of(node->link.prev, node, link);
}
} else {
mode = "text";
str = start;
if(!wl_list_empty(&modes)) {
start = (node->str - tmp - 1) + tmp2;
*start = 0;
++start;
}
}
} else {
if(strcmp(mode, "img") == 0 && create_widgets) {
GdkPixbuf* buf = gdk_pixbuf_new_from_file(str, NULL);
int width = gdk_pixbuf_get_width(buf);
int height = gdk_pixbuf_get_height(buf);
if(height > width) {
float percent = (float) image_size / height;
GdkPixbuf* tmp = gdk_pixbuf_scale_simple(buf, width * percent, image_size, GDK_INTERP_BILINEAR);
g_object_unref(buf);
buf = tmp;
} else {
float percent = (float) image_size / width;
GdkPixbuf* tmp = gdk_pixbuf_scale_simple(buf, image_size, height * percent, GDK_INTERP_BILINEAR);
g_object_unref(buf);
buf = tmp;
}
GtkWidget* img = gtk_image_new_from_pixbuf(buf);
gtk_widget_set_name(img, "img");
gtk_container_add(GTK_CONTAINER(box), img);
} else if(strcmp(mode, "text") == 0) {
if(create_widgets) {
GtkWidget* label = gtk_label_new(str);
gtk_widget_set_name(label, "text");
gtk_label_set_use_markup(GTK_LABEL(label), allow_markup);
gtk_label_set_xalign(GTK_LABEL(label), 0);
gtk_container_add(GTK_CONTAINER(box), label);
} else {
char* tmp = ret;
ret = utils_concat(2, ret, str);
free(tmp);
}
}
mode = NULL;
if(wl_list_empty(&modes)) {
break;
}
}
}
free(tmp);
free(tmp2);
map_free(mode_map);
struct node* tmp_node;
wl_list_for_each_safe(node, tmp_node, &modes, link) {
wl_list_remove(&node->link);
free(node);
}
if(create_widgets) {
free(ret);
return NULL;
} else {
return ret;
}
}
char* wofi_parse_image_escapes(const char* text) {
return parse_images(NULL, text, false);
}
static GtkWidget* create_label(char* mode, char* text, char* search_text, char* action) {
GtkWidget* box = wofi_property_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_name(box, "unselected");
GtkStyleContext* style = gtk_widget_get_style_context(box);
gtk_style_context_add_class(style, "entry");
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "mode", mode);
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "action", action);
if(allow_images) {
parse_images(WOFI_PROPERTY_BOX(box), text, true);
} else {
GtkWidget* label = gtk_label_new(text);
gtk_widget_set_name(label, "text");
gtk_label_set_use_markup(GTK_LABEL(label), allow_markup);
gtk_label_set_xalign(GTK_LABEL(label), 0);
gtk_container_add(GTK_CONTAINER(box), label);
}
if(parse_search) {
search_text = strdup(search_text);
if(allow_images) {
char* tmp = search_text;
search_text = parse_images(WOFI_PROPERTY_BOX(box), search_text, false);
free(tmp);
}
if(allow_markup) {
char* out;
pango_parse_markup(search_text, -1, 0, NULL, &out, NULL, NULL);
free(search_text);
search_text = out;
}
}
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "filter", search_text);
if(parse_search) {
free(search_text);
}
return box;
}
static char* get_cache_path(const gchar* mode) {
if(cache_file != NULL) {
return strdup(cache_file);
}
char* cache_path = getenv("XDG_CACHE_HOME");
if(cache_path == NULL) {
cache_path = utils_concat(3, getenv("HOME"), "/.cache/wofi-", mode);
} else {
cache_path = utils_concat(3, cache_path, "/wofi-", mode);
}
return cache_path;
}
static void execute_action(const gchar* mode, const gchar* cmd) {
struct mode* mode_ptr = map_get(modes, mode);
mode_ptr->mode_exec(cmd);
}
static void activate_item(GtkFlowBox* flow_box, GtkFlowBoxChild* row, gpointer data) {
(void) flow_box;
(void) data;
GtkWidget* box = gtk_bin_get_child(GTK_BIN(row));
bool primary_action = GTK_IS_EXPANDER(box);
if(primary_action) {
box = gtk_expander_get_label_widget(GTK_EXPANDER(box));
}
execute_action(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "mode"), wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "action"));
}
static void expand(GtkExpander* expander, gpointer data) {
(void) data;
GtkWidget* box = gtk_bin_get_child(GTK_BIN(expander));
gtk_widget_set_visible(box, !gtk_expander_get_expanded(expander));
}
static gboolean _insert_widget(gpointer data) {
struct node* node = data;
GtkWidget* parent;
if(node->action_count > 1) {
parent = gtk_expander_new("");
g_signal_connect(parent, "activate", G_CALLBACK(expand), NULL);
GtkWidget* box = create_label(node->mode, node->text[0], node->search_text, node->actions[0]);
gtk_expander_set_label_widget(GTK_EXPANDER(parent), box);
GtkWidget* exp_box = gtk_list_box_new();
gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX(exp_box), FALSE);
g_signal_connect(exp_box, "row-activated", G_CALLBACK(activate_item), NULL);
gtk_container_add(GTK_CONTAINER(parent), exp_box);
for(size_t count = 1; count < node->action_count; ++count) {
box = create_label(node->mode, node->text[count], node->search_text, node->actions[count]);
gtk_container_add(GTK_CONTAINER(exp_box), box);
}
} else {
parent = create_label(node->mode, node->text[0], node->search_text, node->actions[0]);
}
gtk_container_add(GTK_CONTAINER(inner_box), parent);
gtk_widget_show_all(parent);
if(GTK_IS_EXPANDER(parent)) {
GtkWidget* box = gtk_bin_get_child(GTK_BIN(parent));
gtk_widget_set_visible(box, FALSE);
}
free(node->mode);
for(size_t count = 0; count < node->action_count; ++count) {
free(node->text[count]);
}
free(node->text);
free(node->search_text);
for(size_t count = 0; count < node->action_count; ++count) {
free(node->actions[count]);
}
free(node->actions);
free(node);
return FALSE;
}
void wofi_write_cache(const gchar* mode, const gchar* cmd) {
char* cache_path = get_cache_path(mode);
struct wl_list lines;
wl_list_init(&lines);
bool inc_count = false;
if(access(cache_path, R_OK) == 0) {
FILE* file = fopen(cache_path, "r");
char* line = NULL;
size_t size = 0;
while(getline(&line, &size, file) != -1) {
char* space = strchr(line, ' ');
char* nl = strchr(line, '\n');
if(nl != NULL) {
*nl = 0;
}
if(space != NULL && strcmp(cmd, space + 1) == 0) {
struct cache_line* node = malloc(sizeof(struct cache_line));
uint64_t count = strtol(line, NULL, 10) + 1;
char num[6];
snprintf(num, 5, "%" PRIu64, count);
node->line = utils_concat(4, num, " ", cmd, "\n");
inc_count = true;
wl_list_insert(&lines, &node->link);
}
}
free(line);
line = NULL;
size = 0;
fseek(file, 0, SEEK_SET);
while(getline(&line, &size, file) != -1) {
char* space = strchr(line, ' ');
char* nl = strchr(line, '\n');
if(nl != NULL) {
*nl = 0;
}
if(space == NULL || strcmp(cmd, space + 1) != 0) {
struct cache_line* node = malloc(sizeof(struct cache_line));
node->line = utils_concat(2, line, "\n");
wl_list_insert(&lines, &node->link);
}
}
free(line);
fclose(file);
}
if(!inc_count) {
struct cache_line* node = malloc(sizeof(struct cache_line));
node->line = utils_concat(3, "1 ", cmd, "\n");
wl_list_insert(&lines, &node->link);
}
FILE* file = fopen(cache_path, "w");
struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, &lines, link) {
fwrite(node->line, 1, strlen(node->line), file);
free(node->line);
wl_list_remove(&node->link);
free(node);
}
fclose(file);
free(cache_path);
}
struct wl_list* wofi_read_cache(char* mode) {
char* cache_path = get_cache_path(mode);
struct wl_list* cache = malloc(sizeof(struct wl_list));
wl_list_init(cache);
struct wl_list lines;
wl_list_init(&lines);
if(access(cache_path, R_OK) == 0) {
FILE* file = fopen(cache_path, "r");
char* line = NULL;
size_t size = 0;
while(getline(&line, &size, file) != -1) {
struct cache_line* node = malloc(sizeof(struct cache_line));
char* lf = strchr(line, '\n');
if(lf != NULL) {
*lf = 0;
}
node->line = strdup(line);
wl_list_insert(&lines, &node->link);
}
free(line);
fclose(file);
}
while(wl_list_length(&lines) > 0) {
uint64_t smallest = UINT64_MAX;
struct cache_line* node, *smallest_node = NULL;
wl_list_for_each(node, &lines, link) {
uint64_t num = strtol(node->line, NULL, 10);
if(num < smallest) {
smallest = num;
smallest_node = node;
}
}
char* tmp = strdup(strchr(smallest_node->line, ' ') + 1);
free(smallest_node->line);
smallest_node->line = tmp;
wl_list_remove(&smallest_node->link);
wl_list_insert(cache, &smallest_node->link);
}
free(cache_path);
return cache;
}
void wofi_insert_widget(char* mode, char** text, char* search_text, char** actions, size_t action_count) {
struct node* widget = malloc(sizeof(struct node));
widget->mode = strdup(mode);
widget->text = malloc(action_count * sizeof(char*));
for(size_t count = 0; count < action_count; ++count) {
widget->text[count] = strdup(text[count]);
}
widget->search_text = strdup(search_text);
widget->action_count = action_count;
widget->actions = malloc(action_count * sizeof(char*));
for(size_t count = 0; count < action_count; ++count) {
widget->actions[count] = strdup(actions[count]);
}
g_idle_add(_insert_widget, widget);
utils_sleep_millis(1);
}
bool wofi_allow_images() {
return allow_images;
}
bool wofi_allow_markup() {
return allow_markup;
}
uint64_t wofi_get_image_size() {
return image_size;
}
bool wofi_mod_shift() {
return mod_shift;
}
bool wofi_mod_control() {
return mod_ctrl;
}
void wofi_term_run(const char* cmd) {
if(terminal != NULL) {
execlp(terminal, terminal, "--", cmd, NULL);
}
size_t term_count = sizeof(terminals) / sizeof(char*);
for(size_t count = 0; count < term_count; ++count) {
execlp(terminals[count], terminals[count], "--", cmd, NULL);
}
fprintf(stderr, "No terminal emulator found please set term in config or use --term\n");
exit(1);
}
static void select_item(GtkFlowBox* flow_box, gpointer data) {
(void) data;
if(previous_selection != NULL) {
gtk_widget_set_name(previous_selection, "unselected");
}
GList* selected_children = gtk_flow_box_get_selected_children(flow_box);
GtkWidget* box = gtk_bin_get_child(GTK_BIN(selected_children->data));
g_list_free(selected_children);
gtk_widget_set_name(box, "selected");
previous_selection = box;
}
static GtkWidget* get_first_child(GtkContainer* container) {
GList* children = gtk_container_get_children(container);
GList* list = children;
GtkWidget* min_child = NULL;
int64_t x = INT64_MAX;
int64_t y = INT64_MAX;
for(; list != NULL; list = list->next) {
GtkWidget* child = list->data;
GtkAllocation alloc;
gtk_widget_get_allocation(child, &alloc);
if(alloc.x <= x && alloc.y <= y && alloc.x != -1 && alloc.y != -1 && alloc.width != 1 && alloc.height != 1 && gtk_widget_get_child_visible(child)) {
x = alloc.x;
y = alloc.y;
min_child = child;
}
}
g_list_free(children);
return min_child;
}
static void activate_search(GtkEntry* entry, gpointer data) {
(void) data;
GtkWidget* child = get_first_child(GTK_CONTAINER(inner_box));
if(exec_search || child == NULL) {
execute_action(mode, gtk_entry_get_text(entry));
} else {
GtkWidget* box = gtk_bin_get_child(GTK_BIN(child));
bool primary_action = GTK_IS_EXPANDER(box);
if(primary_action) {
box = gtk_expander_get_label_widget(GTK_EXPANDER(box));
}
execute_action(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "mode"), wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "action"));
}
}
static gboolean do_filter(GtkFlowBoxChild* row, gpointer data) {
(void) data;
GtkWidget* box = gtk_bin_get_child(GTK_BIN(row));
if(GTK_IS_EXPANDER(box)) {
box = gtk_expander_get_label_widget(GTK_EXPANDER(box));
}
const gchar* text = wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "filter");
if(filter == NULL || strcmp(filter, "") == 0) {
return TRUE;
}
if(text == NULL) {
return FALSE;
}
if(insensitive) {
return strcasestr(text, filter) != NULL;
} else {
return strstr(text, filter) != NULL;
}
}
static gint do_sort(GtkFlowBoxChild* child1, GtkFlowBoxChild* child2, gpointer data) {
(void) data;
GtkWidget* box1 = gtk_bin_get_child(GTK_BIN(child1));
GtkWidget* box2 = gtk_bin_get_child(GTK_BIN(child2));
if(GTK_IS_EXPANDER(box1)) {
box1 = gtk_expander_get_label_widget(GTK_EXPANDER(box1));
}
if(GTK_IS_EXPANDER(box2)) {
box2 = gtk_expander_get_label_widget(GTK_EXPANDER(box2));
}
const gchar* text1 = wofi_property_box_get_property(WOFI_PROPERTY_BOX(box1), "filter");
const gchar* text2 = wofi_property_box_get_property(WOFI_PROPERTY_BOX(box2), "filter");
if(filter == NULL || strcmp(filter, "") == 0) {
return 0;
}
if(text1 == NULL || text2 == NULL) {
return 0;
}
size_t dist1 = utils_distance(text1, filter);
size_t dist2 = utils_distance(text2, filter);
if(dist1 < dist2) {
return -1;
} else if(dist1 > dist2) {
return 1;
} else {
return 0;
}
}
static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) {
(void) widget;
(void) data;
switch(event->key.keyval) {
case GDK_KEY_Escape:
exit(0);
break;
case GDK_KEY_Up:
case GDK_KEY_Left:
break;
case GDK_KEY_Return:
mod_shift = (event->key.state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK;
mod_ctrl = (event->key.state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
if(mod_shift) {
event->key.state &= ~GDK_SHIFT_MASK;
}
if(mod_ctrl) {
event->key.state &= ~GDK_CONTROL_MASK;
}
if(gtk_widget_has_focus(scroll)) {
gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry));
}
break;
case GDK_KEY_Tab:
case GDK_KEY_Down:
case GDK_KEY_Right:
if(event->key.keyval == GDK_KEY_Down && outer_orientation == GTK_ORIENTATION_HORIZONTAL) {
return FALSE;
} else if(event->key.keyval == GDK_KEY_Right && outer_orientation == GTK_ORIENTATION_VERTICAL) {
return FALSE;
}
if(gtk_widget_has_focus(entry) || gtk_widget_has_focus(scroll)) {
GtkWidget* child = get_first_child(GTK_CONTAINER(inner_box));
gtk_widget_grab_focus(child);
gtk_flow_box_select_child(GTK_FLOW_BOX(inner_box), GTK_FLOW_BOX_CHILD(child));
return TRUE;
}
break;
case GDK_KEY_Shift_L:case GDK_KEY_Shift_R:
case GDK_KEY_Control_L:case GDK_KEY_Control_R:
break;
default:
if(!gtk_widget_has_focus(entry)) {
gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry));
}
break;
}
return FALSE;
}
static void* get_plugin_proc(const char* prefix, const char* suffix) {
char* proc_name = utils_concat(3, "wofi_", prefix, suffix);
void* proc = dlsym(RTLD_DEFAULT, proc_name);
free(proc_name);
return proc;
}
static void add_mode(char* mode) {
char* dso = strstr(mode, ".so");
struct mode* mode_ptr = calloc(1, sizeof(struct mode));
map_put_void(modes, mode, mode_ptr);
void (*init)(struct map* props);
const char** (*get_arg_names)();
size_t (*get_arg_count)();
if(dso == NULL) {
init = get_plugin_proc(mode, "_init");
get_arg_names = get_plugin_proc(mode, "_get_arg_names");
get_arg_count = get_plugin_proc(mode, "_get_arg_count");
mode_ptr->mode_exec = get_plugin_proc(mode, "_exec");
} else {
char* plugins_dir = utils_concat(2, config_dir, "/plugins/");
char* full_name = utils_concat(2, plugins_dir, mode);
void* plugin = dlopen(full_name, RTLD_LAZY | RTLD_LOCAL);
free(full_name);
free(plugins_dir);
init = dlsym(plugin, "init");
get_arg_names = dlsym(plugin, "get_arg_names");
get_arg_count = dlsym(plugin, "get_arg_count");
mode_ptr->mode_exec = dlsym(plugin, "exec");
}
const char** arg_names = NULL;
size_t arg_count = 0;
if(get_arg_names != NULL && get_arg_count != NULL) {
arg_names = get_arg_names();
arg_count = get_arg_count();
}
struct map* props = map_init();
for(size_t count = 0; count < arg_count; ++count) {
const char* arg = arg_names[count];
char* full_name = utils_concat(3, mode, "-", arg);
map_put(props, arg, config_get(config, full_name, NULL));
free(full_name);
}
if(init != NULL) {
init(props);
} else {
fprintf(stderr, "I would love to show %s but Idk what it is\n", mode);
exit(1);
}
map_free(props);
}
static void* start_thread(void* data) {
(void) data;
if(strchr(mode, ',') != NULL) {
char* save_ptr;
char* str = strtok_r(mode, ",", &save_ptr);
do {
add_mode(str);
} while((str = strtok_r(NULL, ",", &save_ptr)) != NULL);
} else {
add_mode(mode);
}
return NULL;
}
void wofi_init(struct map* _config) {
config = _config;
width = strtol(config_get(config, "width", "1000"), NULL, 10);
height = strtol(config_get(config, "height", "400"), NULL, 10);
x = strtol(config_get(config, "x", "-1"), NULL, 10);
y = strtol(config_get(config, "y", "-1"), NULL, 10);
bool normal_window = strcmp(config_get(config, "normal_window", "false"), "true") == 0;
mode = map_get(config, "mode");
uint8_t orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "vertical", "horizontal");
outer_orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "horizontal", "vertical");
uint8_t halign = config_get_mnemonic(config, "halign", "fill", 4, "fill", "start", "end", "center");
char* default_valign = "start";
if(outer_orientation == GTK_ORIENTATION_HORIZONTAL) {
default_valign = "center";
}
uint8_t valign = config_get_mnemonic(config, "valign", default_valign, 4, "fill", "start", "end", "center");
char* prompt = config_get(config, "prompt", mode);
filter_rate = strtol(config_get(config, "filter_rate", "100"), NULL, 10);
filter_time = utils_get_time_millis();
allow_images = strcmp(config_get(config, "allow_images", "false"), "true") == 0;
allow_markup = strcmp(config_get(config, "allow_markup", "false"), "true") == 0;
image_size = strtol(config_get(config, "image_size", "32"), NULL, 10);
cache_file = map_get(config, "cache_file");
config_dir = map_get(config, "config_dir");
terminal = map_get(config, "term");
char* password_char = map_get(config, "password_char");
exec_search = strcmp(config_get(config, "exec_search", "false"), "true") == 0;
bool hide_scroll = strcmp(config_get(config, "hide_scroll", "false"), "true") == 0;
matching = config_get_mnemonic(config, "matching", "contains", 2, "contains", "fuzzy");
insensitive = strcmp(config_get(config, "insensitive", "false"), "true") == 0;
parse_search = strcmp(config_get(config, "parse_search", "false"), "true") == 0;
modes = map_init_void();
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_realize(window);
gtk_widget_set_name(window, "window");
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
gtk_window_resize(GTK_WINDOW(window), width, height);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
if(!normal_window) {
GdkDisplay* disp = gdk_display_get_default();
struct wl_display* wl = gdk_wayland_display_get_wl_display(disp);
struct wl_registry* registry = wl_display_get_registry(wl);
struct wl_registry_listener listener = {
.global = add_interface,
.global_remove = nop
};
wl_registry_add_listener(registry, &listener, NULL);
wl_display_roundtrip(wl);
GdkWindow* gdk_win = gtk_widget_get_window(window);
gdk_wayland_window_set_use_custom_surface(gdk_win);
struct wl_surface* wl_surface = gdk_wayland_window_get_wl_surface(gdk_win);
struct zwlr_layer_surface_v1* surface = zwlr_layer_shell_v1_get_layer_surface(shell, wl_surface, NULL, ZWLR_LAYER_SHELL_V1_LAYER_TOP, "wofi");
struct zwlr_layer_surface_v1_listener* surface_listener = malloc(sizeof(struct zwlr_layer_surface_v1_listener));
surface_listener->configure = config_surface;
surface_listener->closed = nop;
zwlr_layer_surface_v1_add_listener(surface, surface_listener, NULL);
wl_surface_commit(wl_surface);
wl_display_roundtrip(wl);
}
outer_box = gtk_box_new(outer_orientation, 0);
gtk_widget_set_name(outer_box, "outer-box");
gtk_container_add(GTK_CONTAINER(window), outer_box);
entry = gtk_search_entry_new();
gtk_widget_set_name(entry, "input");
gtk_entry_set_placeholder_text(GTK_ENTRY(entry), prompt);
gtk_container_add(GTK_CONTAINER(outer_box), entry);
if(password_char != NULL) {
gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
gtk_entry_set_invisible_char(GTK_ENTRY(entry), password_char[0]);
}
scroll = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_name(scroll, "scroll");
gtk_container_add(GTK_CONTAINER(outer_box), scroll);
gtk_widget_set_size_request(scroll, width, height);
if(hide_scroll) {
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_EXTERNAL, GTK_POLICY_EXTERNAL);
}
inner_box = gtk_flow_box_new();
gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(inner_box), 1);
gtk_orientable_set_orientation(GTK_ORIENTABLE(inner_box), orientation);
gtk_widget_set_halign(inner_box, halign);
gtk_widget_set_valign(inner_box, valign);
gtk_widget_set_name(inner_box, "inner-box");
gtk_flow_box_set_activate_on_single_click(GTK_FLOW_BOX(inner_box), FALSE);
GtkWidget* wrapper_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_set_homogeneous(GTK_BOX(wrapper_box), TRUE);
gtk_container_add(GTK_CONTAINER(wrapper_box), inner_box);
gtk_container_add(GTK_CONTAINER(scroll), wrapper_box);
switch(matching) {
case MATCHING_MODE_CONTAINS:
gtk_flow_box_set_filter_func(GTK_FLOW_BOX(inner_box), do_filter, NULL, NULL);
break;
case MATCHING_MODE_FUZZY:
gtk_flow_box_set_sort_func(GTK_FLOW_BOX(inner_box), do_sort, NULL, NULL);
break;
}
g_signal_connect(entry, "changed", G_CALLBACK(get_input), NULL);
g_signal_connect(entry, "search-changed", G_CALLBACK(get_search), NULL);
g_signal_connect(inner_box, "child-activated", G_CALLBACK(activate_item), NULL);
g_signal_connect(inner_box, "selected-children-changed", G_CALLBACK(select_item), NULL);
g_signal_connect(entry, "activate", G_CALLBACK(activate_search), NULL);
g_signal_connect(window, "key-press-event", G_CALLBACK(key_press), NULL);
pthread_t thread;
pthread_create(&thread, NULL, start_thread, NULL);
gtk_widget_grab_focus(scroll);
gtk_window_set_title(GTK_WINDOW(window), prompt);
gtk_widget_show_all(window);
}