Beispiel #1
0
        /*
         * Close the notification that has id.
         *
         * reasons:
         * -1 -> notification is a replacement, no NotificationClosed signal emitted
         *  1 -> the notification expired
         *  2 -> the notification was dismissed by the user_data
         *  3 -> The notification was closed by a call to CloseNotification
         */
int notification_close_by_id(int id, int reason)
{
        notification *target = NULL;

        for (GList * iter = g_queue_peek_head_link(displayed); iter;
             iter = iter->next) {
                notification *n = iter->data;
                if (n->id == id) {
                        g_queue_remove(displayed, n);
                        history_push(n);
                        target = n;
                        break;
                }
        }

        for (GList * iter = g_queue_peek_head_link(queue); iter;
             iter = iter->next) {
                notification *n = iter->data;
                if (n->id == id) {
                        g_queue_remove(queue, n);
                        history_push(n);
                        target = n;
                        break;
                }
        }

        if (reason > 0 && reason < 4 && target != NULL) {
                notificationClosed(target, reason);
        }

        wake_up();
        return reason;
}
Beispiel #2
0
void			builtin_fc_list(t_argparser_result *result)
{
	int			first_index;
	int			second_index;
	t_line		*save;

	if (!history_get_first(edit_singleton()->history))
		save = NULL;
	else
	{
		save = line_copy(history_get_from_last(edit_singleton()->history, 0));
		history_pop_last(edit_singleton()->history);
	}
	builtin_fc_list_get_indexes(result, &first_index, &second_index);
	if (first_index == -1 || second_index == -1)
	{
		shenv_singl_error(1, "fc: history specification out of range");
		return ;
	}
	if (argparser_result_opt_is_set(result, "r"))
		list_reverse(result, first_index, second_index);
	else
		list_normal(result, first_index, second_index);
	if (save)
		history_push(edit_singleton()->history, save);
}
Beispiel #3
0
void MeshData::triangulate(int idx) {
  auto copy0 = std::unique_ptr<Surface_mesh> {new Surface_mesh(get_mesh(0))};
  auto copy1 = std::unique_ptr<Surface_mesh> {new Surface_mesh(get_mesh(1))};

  qDebug() << "Triangulating mesh" << idx;

  if (idx == 0) {
    copy0->triangulate();
  } else {
    copy1->triangulate();
  }
  history_push({std::move(copy0), std::move(copy1)});

  emit_updated_signal();
}
Beispiel #4
0
bool MeshData::load(const std::string& filename) {
  if (filename.empty()) {
    qWarning() << "File name empty. Aborting loading.";
    return false;
  }

  qDebug() << "Loading mesh from file:" << QString::fromStdString(filename);
  // create new mesh where the file will be loaded into
  auto mesh_from_file = std::unique_ptr<Surface_mesh> {new Surface_mesh};
  bool success = mesh_from_file->read(filename);
  auto copy = std::unique_ptr<Surface_mesh> {new Surface_mesh(*mesh_from_file.get())};
  original_mesh_ = std::unique_ptr<Surface_mesh> {new Surface_mesh(*mesh_from_file.get())};
  history_push({std::move(mesh_from_file), std::move(copy)});
  emit_updated_signal();

  return success;
}
Beispiel #5
0
        /*
         * Initialize the given notification and add it to
         * the queue. Replace notification with id if id > 0.
         */
int notification_init(notification * n, int id)
{

        if (n == NULL)
                return -1;

        if (strcmp("DUNST_COMMAND_PAUSE", n->summary) == 0) {
                pause_display = true;
                return 0;
        }

        if (strcmp("DUNST_COMMAND_RESUME", n->summary) == 0) {
                pause_display = false;
                return 0;
        }

        n->script = NULL;
        n->text_to_render = NULL;

        n->format = settings.format;

        rule_apply_all(n);

        n->urls = notification_extract_markup_urls(&(n->body));

        n->msg = string_replace("%a", n->appname, g_strdup(n->format));
        n->msg = string_replace("%s", n->summary, n->msg);
        if (n->icon) {
                n->msg = string_replace("%I", basename(n->icon), n->msg);
                n->msg = string_replace("%i", n->icon, n->msg);
        }
        n->msg = string_replace("%b", n->body, n->msg);
        if (n->progress) {
                char pg[10];
                sprintf(pg, "[%3d%%]", n->progress - 1);
                n->msg = string_replace("%p", pg, n->msg);
        } else {
                n->msg = string_replace("%p", "", n->msg);
        }

        if (!settings.allow_markup)
                n->msg = notification_fix_markup(n->msg);
        else if (!settings.ignore_newline) {
                n->msg = string_replace("<br>", "\n", n->msg);
                n->msg = string_replace("<br />", "\n", n->msg);
        }

        while (strstr(n->msg, "\\n") != NULL)
                n->msg = string_replace("\\n", "\n", n->msg);

        if (settings.ignore_newline)
                while (strstr(n->msg, "\n") != NULL)
                        n->msg = string_replace("\n", " ", n->msg);

        n->msg = g_strstrip(n->msg);

        if (id == 0) {
                n->id = ++next_notification_id;
        } else {
                notification_close_by_id(id, -1);
                n->id = id;
        }

        n->dup_count = 0;

        /* check if n is a duplicate */
        if (settings.stack_duplicates) {
                for (GList * iter = g_queue_peek_head_link(queue); iter;
                     iter = iter->next) {
                        notification *orig = iter->data;
                        if (strcmp(orig->appname, n->appname) == 0
                            && strcmp(orig->summary, n->summary) == 0
                            && strcmp(orig->body, n->body) == 0) {
                                /* If the progress differs this was probably intended to replace the notification
                                 * but notify-send was used. So don't increment dup_count in this case
                                 */
                                if (orig->progress == n->progress) {
                                        orig->dup_count++;
                                } else {
                                        orig->progress = n->progress;
                                }
                                /* notifications that differ only in progress hints should be expected equal,
                                 * but we want the latest message, with the latest hint value
                                 */
                                free(orig->msg);
                                orig->msg = strdup(n->msg);
                                notification_free(n);
                                wake_up();
                                return orig->id;
                        }
                }

                for (GList * iter = g_queue_peek_head_link(displayed); iter;
                     iter = iter->next) {
                        notification *orig = iter->data;
                        if (strcmp(orig->appname, n->appname) == 0
                            && strcmp(orig->summary, n->summary) == 0
                            && strcmp(orig->body, n->body) == 0) {
                                /* notifications that differ only in progress hints should be expected equal,
                                 * but we want the latest message, with the latest hint value
                                 */
                                free(orig->msg);
                                orig->msg = strdup(n->msg);
                                /* If the progress differs this was probably intended to replace the notification
                                 * but notify-send was used. So don't increment dup_count in this case
                                 */
                                if (orig->progress == n->progress) {
                                        orig->dup_count++;
                                } else {
                                        orig->progress = n->progress;
                                }
                                orig->start = time(NULL);
                                notification_free(n);
                                wake_up();
                                return orig->id;
                        }
                }
        }

        /* urgency > CRIT -> array out of range */
        n->urgency = n->urgency > CRIT ? CRIT : n->urgency;

        if (!n->color_strings[ColFG]) {
                n->color_strings[ColFG] = xctx.color_strings[ColFG][n->urgency];
        }

        if (!n->color_strings[ColBG]) {
                n->color_strings[ColBG] = xctx.color_strings[ColBG][n->urgency];
        }

        n->timeout =
            n->timeout == -1 ? settings.timeouts[n->urgency] : n->timeout;
        n->start = 0;

        if (n->icon == NULL) {
                n->icon = strdup(settings.icons[n->urgency]);
        }
        else if (strlen(n->icon) <= 0) {
                free(n->icon);
                n->icon = strdup(settings.icons[n->urgency]);
        }

        if (n->category == NULL) {
                n->category = "";
        }

        n->timestamp = time(NULL);

        n->redisplayed = false;

        n->first_render = true;

        if (strlen(n->msg) == 0) {
                notification_close(n, 2);
                printf("skipping notification: %s %s\n", n->body, n->summary);
        } else {
//                g_queue_insert_sorted(queue, n, notification_cmp_data, NULL);
                history_push(n);
        }

        char *tmp = g_strconcat(n->summary, " ", n->body, NULL);

        char *tmp_urls = extract_urls(tmp);
        if (tmp_urls != NULL) {
            if (n->urls != NULL) {
                n->urls = string_append(n->urls, tmp_urls, "\n");
                free(tmp_urls);
            } else {
                n->urls = tmp_urls;
            }
        }

        if (n->actions) {
                n->actions->dmenu_str = NULL;
                for (int i = 0; i < n->actions->count; i += 2) {
                        char *human_readable = n->actions->actions[i + 1];
                        string_replace_char('[', '(', human_readable); // kill square brackets
                        string_replace_char(']', ')', human_readable);

                        n->actions->dmenu_str =
                            string_append(n->actions->dmenu_str,
                                          g_strdup_printf("#%s [%s]", human_readable,
                                                                      n->appname),
                                          "\n");
                }
        }

        free(tmp);

        if (settings.print_notifications)
                notification_print(n);

        return n->id;
}
Beispiel #6
0
void MeshData::load(MeshPairUniquePtrs meshes) {
  qDebug() << "Mesh pair loaded";
  history_push({std::move(meshes.first), std::move(meshes.second)});
  emit_updated_signal();
}